manifoldcf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1564296 - in /manifoldcf/trunk: CHANGES.txt framework/core/src/main/java/org/apache/manifoldcf/core/throttler/ConnectionBin.java
Date Tue, 04 Feb 2014 13:35:13 GMT
Author: kwright
Date: Tue Feb  4 13:35:13 2014
New Revision: 1564296

URL: http://svn.apache.org/r1564296
Log:
Fix for CONNECTORS-878.

Modified:
    manifoldcf/trunk/CHANGES.txt
    manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/ConnectionBin.java

Modified: manifoldcf/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/CHANGES.txt?rev=1564296&r1=1564295&r2=1564296&view=diff
==============================================================================
--- manifoldcf/trunk/CHANGES.txt (original)
+++ manifoldcf/trunk/CHANGES.txt Tue Feb  4 13:35:13 2014
@@ -3,6 +3,10 @@ $Id$
 
 ======================= 1.6-dev =====================
 
+CONNECTORS-878: Come up with a formula for allocating connections
+to pools when a connection bin is used by multiple pools.
+(Karl Wright)
+
 CONNECTORS-877: Missing Solr i18n key.
 (Erlend Garåsen, Karl Wright)
 

Modified: manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/ConnectionBin.java
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/ConnectionBin.java?rev=1564296&r1=1564295&r2=1564296&view=diff
==============================================================================
--- manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/ConnectionBin.java
(original)
+++ manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/ConnectionBin.java
Tue Feb  4 13:35:13 2014
@@ -65,7 +65,11 @@ public class ConnectionBin
   /** This is the number of connections in this bin that are connected; immaterial whether
they are
   * in use or in a pool somewhere. */
   protected int inUseConnections = 0;
-
+  /** This is the number of active referring connection pools.  We increment this number
+  * whenever a poolCount goes from zero to 1, and we decrement it whenever a poolCount
+  * goes from one to zero. */
+  protected int referencingPools = 0;
+  
   /** The service type prefix for connection bins */
   protected final static String serviceTypePrefix = "_CONNECTIONBIN_";
 
@@ -136,6 +140,8 @@ public class ConnectionBin
       {
         // Recommendation is to pull the connection from the pool.
         poolCount.set(currentPoolCount - 1);
+        if (currentPoolCount == 1)
+          referencingPools--;
         return IConnectionThrottler.CONNECTION_FROM_POOL;
       }
       if (inUseConnections + reservedConnections < localMax)
@@ -162,7 +168,10 @@ public class ConnectionBin
     }
     else if (recommendation == IConnectionThrottler.CONNECTION_FROM_POOL)
     {
-      poolCount.set(poolCount.get() + 1);
+      int currentCount = poolCount.get();
+      poolCount.set(currentCount + 1);
+      if (currentCount == 0)
+        referencingPools++;
       notifyAll();
     }
   }
@@ -203,18 +212,18 @@ public class ConnectionBin
     int currentPoolCount = poolCount.get();
     if (currentPoolCount > 0)
     {
+      int individualPoolAllocation = localMax / referencingPools;
       // Consider it removed from the pool for the purposes of consideration.  If we change
our minds, we'll
       // return it, and no harm done.
       poolCount.set(currentPoolCount-1);
+      if (currentPoolCount == 1)
+        referencingPools--;
       // We don't count reserved connections here because those are not yet committed.
-      if (inUseConnections > localMax)
+      if (inUseConnections > individualPoolAllocation)
       {
         return CONNECTION_DESTROY;
       }
-      // Hack: always return CONNECTION_DESTROY, because we don't have a good way of allocating
-      // connections in multiple pools that share the same connection bin.  See CONNECTORS-872.
-      //return CONNECTION_WITHINBOUNDS;
-      return CONNECTION_DESTROY;
+      return CONNECTION_WITHINBOUNDS;
     }
     return CONNECTION_POOLEMPTY;
   }
@@ -227,6 +236,8 @@ public class ConnectionBin
     if (currentPoolCount > 0)
     {
       poolCount.set(currentPoolCount-1);
+      if (currentPoolCount == 1)
+        referencingPools--;
       return true;
     }
     return false;
@@ -236,7 +247,10 @@ public class ConnectionBin
   */
   public synchronized void undoPooledConnectionDecision(AtomicInteger poolCount)
   {
-    poolCount.set(poolCount.get() + 1);
+    int currentPoolCount = poolCount.get();
+    poolCount.set(currentPoolCount + 1);
+    if (currentPoolCount == 0)
+      referencingPools++;
     notifyAll();
   }
   
@@ -244,7 +258,10 @@ public class ConnectionBin
   */
   public synchronized void noteConnectionReturnedToPool(AtomicInteger poolCount)
   {
-    poolCount.set(poolCount.get() + 1);
+    int currentPoolCount = poolCount.get();
+    poolCount.set(currentPoolCount + 1);
+    if (currentPoolCount == 0)
+      referencingPools++;
     // Wake up threads possibly waiting on a pool return.
     notifyAll();
   }



Mime
View raw message