Revision: 15463
Author: brainslog
Date: Tue Nov 23 18:02:57 2010
Log: Removes Diameter Stack performance bottleneck at registerRequestRouteInfo

Update Issue 2154
Status: Fixed
By replacing iteration of list containing ordered request info and removing it both from a HashMap and from a CopyOnWriteArrayList by removing a first-half subList from the HashMap keySet and creating a new CopyOnWriteArrayList with the second-half subList, the time wasted for this method has been greatly improved, mainly on the latter.
This method should not limit performance anymore.


http://code.google.com/p/mobicents/source/detail?r=15463

Modified:
/trunk/servers/diameter/core/jdiameter/impl/src/main/java/org/jdiameter/client/impl/router/RouterImpl.java

=======================================
--- /trunk/servers/diameter/core/jdiameter/impl/src/main/java/org/jdiameter/client/impl/router/RouterImpl.java Sat Jun 5 19:07:39 2010 +++ /trunk/servers/diameter/core/jdiameter/impl/src/main/java/org/jdiameter/client/impl/router/RouterImpl.java Tue Nov 23 18:02:57 2010
@@ -24,6 +24,7 @@

 import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.TimeUnit;
@@ -63,7 +64,7 @@
     public static final int REQUEST_TABLE_CLEAR_SIZE = 5 * 1024;
     protected ReadWriteLock requestLock = new ReentrantReadWriteLock();
protected Map<Long, AnswerEntry> requestEntryTable = new ConcurrentHashMap<Long, AnswerEntry>(REQUEST_TABLE_SIZE); - protected List<Long> requestSortedEntryTable = new java.util.concurrent.CopyOnWriteArrayList<Long>(); + protected List<Long> requestSortedEntryTable = new CopyOnWriteArrayList<Long>();
     protected boolean isStopped = true;

public RouterImpl(IConcurrentFactory concurrentFactory, Configuration config, MetaData aMetaData) {
@@ -110,10 +111,16 @@
             requestEntryTable.put(hopByHopId, entry);
             requestSortedEntryTable.add(hopByHopId);
             if (requestEntryTable.size() > REQUEST_TABLE_SIZE) {
-              for (int i = 0; i < REQUEST_TABLE_CLEAR_SIZE; i++) {
-                Long lastKey = requestSortedEntryTable.remove(0);
-                requestEntryTable.remove(lastKey);
-              }
+ concurrentFactory.getThread("jDiameterRouterCleaning", new Runnable() {
+                public void run() {
+ List<Long> toRemove = requestSortedEntryTable.subList(0, REQUEST_TABLE_CLEAR_SIZE);
+                  // removing from keyset removes from hashmap too
+                  requestEntryTable.keySet().removeAll(toRemove);
+ // instead of wasting time removing, just make a new one, much faster + requestSortedEntryTable = new CopyOnWriteArrayList<Long>(requestSortedEntryTable.subList(REQUEST_TABLE_CLEAR_SIZE, requestSortedEntryTable.size()));
+                  toRemove = null;
+                }
+              }).run();
             }
         }
         catch (Exception e) {

Reply via email to