BUG-3157: performance tuning - Use a TrieMap as the ConcurrentMap implementation 54/22354/2
authorRobert Varga <rovarga@cisco.com>
Sat, 6 Jun 2015 01:44:24 +0000 (03:44 +0200)
committermichal rehak <mirehak@cisco.com>
Thu, 11 Jun 2015 12:01:42 +0000 (12:01 +0000)
TrieMap is space-optimized and has a high fanout, which means it will
reclaim space when not needed and has shallower structure than a
ConcurrentHashMap. It also re-hashes automatically and concurrently.

Change-Id: I1e40dbb5588c1e42475e12d73f7cadf46b909594
Signed-off-by: Robert Varga <rovarga@cisco.com>
(cherry picked from commit 5faeb7ea76404e4da3620e63432b6038800d4de7)

openflowplugin-impl/pom.xml
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/registry/flow/DeviceFlowRegistryImpl.java

index f5edb1e3e09bca258dd49e8a9c4fe905128bf062..8b6cad7ae645c2cc85d20fb130103149adc319c6 100644 (file)
             <groupId>org.apache.commons</groupId>
             <artifactId>commons-lang3</artifactId>
         </dependency>
+        <dependency>
+            <groupId>com.github.romix</groupId>
+            <artifactId>java-concurrent-hash-trie-map</artifactId>
+        </dependency>
 
         <dependency>
             <groupId>junit</groupId>
index 16e5ce9ad5bf26b82c461fe5acbf4fcc55541621..e34b8292697aa0a38dae50aeb372fdd50b107b20 100644 (file)
@@ -7,11 +7,11 @@
  */
 package org.opendaylight.openflowplugin.impl.registry.flow;
 
+import com.romix.scala.collection.concurrent.TrieMap;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 import javax.annotation.concurrent.GuardedBy;
 import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry;
@@ -28,7 +28,7 @@ import org.slf4j.LoggerFactory;
 public class DeviceFlowRegistryImpl implements DeviceFlowRegistry {
     private static final Logger LOG = LoggerFactory.getLogger(DeviceFlowRegistryImpl.class);
 
-    private final ConcurrentMap<FlowRegistryKey, FlowDescriptor> flowRegistry = new ConcurrentHashMap<>();
+    private final ConcurrentMap<FlowRegistryKey, FlowDescriptor> flowRegistry = new TrieMap<>();
     @GuardedBy("marks")
     private final Collection<FlowRegistryKey> marks = new HashSet<>();