Author: rfm
Date: Mon Oct 13 12:47:06 2014
New Revision: 38114

URL: http://svn.gna.org/viewcvs/gnustep?rev=38114&view=rev
Log:
connection pool tweaks

Modified:
    libs/sqlclient/trunk/ChangeLog
    libs/sqlclient/trunk/SQLClient.h
    libs/sqlclient/trunk/SQLClient.m
    libs/sqlclient/trunk/SQLClientPool.m

Modified: libs/sqlclient/trunk/ChangeLog
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/sqlclient/trunk/ChangeLog?rev=38114&r1=38113&r2=38114&view=diff
==============================================================================
--- libs/sqlclient/trunk/ChangeLog      (original)
+++ libs/sqlclient/trunk/ChangeLog      Mon Oct 13 12:47:06 2014
@@ -1,3 +1,12 @@
+2014-10-13 Richard Frith-Macdonald  <[email protected]>
+
+        * SQLClient.h:
+        * SQLClient.m:
+        * SQLClientPool.m:
+       Keep connections in pools outside the normal count of maximum number
+       of concurrent connections.  If we are using a pool then we must
+       assume we want the pool to operate to its configured capacity.
+
 2014-10-07 Richard Frith-Macdonald  <[email protected]>
 
        * SQLClient.m: Add locking of the database client by SQLTransaction

Modified: libs/sqlclient/trunk/SQLClient.h
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/sqlclient/trunk/SQLClient.h?rev=38114&r1=38113&r2=38114&view=diff
==============================================================================
--- libs/sqlclient/trunk/SQLClient.h    (original)
+++ libs/sqlclient/trunk/SQLClient.h    Mon Oct 13 12:47:06 2014
@@ -429,8 +429,9 @@
 + (SQLClient*) existingClient: (NSString*)reference;
 
 /**
- * Return the maximum number of simultaneous database connections
- * permitted (set by +setMaxConnections: and defaults to 8)
+ * Returns the maximum number of simultaneous database connections
+ * permitted (set by +setMaxConnections: and defaults to 8) for
+ * connections outside of SQLClientPool instances.
  */
 + (unsigned int) maxConnections;
 
@@ -447,6 +448,9 @@
  * idle connections, but you can also pass a date in the future to
  * close all connections.
  * </p>
+ * <p>Purging does not apply to connections made by SQLClientPool
+ * instances.
+ * </p>
  */
 + (void) purgeConnections: (NSDate*)since;
 
@@ -456,6 +460,9 @@
  * </p>
  * <p>This value is used by the +purgeConnections: method to determine how
  * many connections should be disconnected when it is called.
+ * </p>
+ * <p>Connections used by SQLClientPool instances are not considered by
+ * this maximum.
  * </p>
  */
 + (void) setMaxConnections: (unsigned int)c;

Modified: libs/sqlclient/trunk/SQLClient.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/sqlclient/trunk/SQLClient.m?rev=38114&r1=38113&r2=38114&view=diff
==============================================================================
--- libs/sqlclient/trunk/SQLClient.m    (original)
+++ libs/sqlclient/trunk/SQLClient.m    Mon Oct 13 12:47:06 2014
@@ -707,6 +707,7 @@
 @implementation        SQLClient
 
 static unsigned int    maxConnections = 8;
+static int             poolConnections = 0;
 
 + (NSArray*) allClients
 {
@@ -844,7 +845,7 @@
   NSEndHashTableEnumeration(&e);
   [clientsLock unlock];
 
-  while (connectionCount >= maxConnections)
+  while (connectionCount >= (maxConnections + poolConnections))
     {
       SQLClient                *other = nil;
       NSTimeInterval   oldest = 0.0;
@@ -872,7 +873,7 @@
       if ([other debugging] > 0)
        {
          [other debug:
-           @"Force disconnect of '%@' because pool size (%d) reached",
+           @"Force disconnect of '%@' because max connections (%u) reached",
            other, maxConnections]; 
        }
       [other disconnect];
@@ -3784,3 +3785,22 @@
 }
 @end
 
+@implementation        SQLClientPool (Adjust)
+
++ (void) _adjustPoolConnections: (int)n
+{
+  unsigned      err = 0;
+
+  [clientsLock lock];
+  poolConnections += n;
+  if (poolConnections < 0)
+    {
+      err -= poolConnections;
+      poolConnections = 0;
+    }
+  [clientsLock unlock];
+  NSAssert(0 == err, NSInvalidArgumentException);
+}
+
+@end
+

Modified: libs/sqlclient/trunk/SQLClientPool.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/sqlclient/trunk/SQLClientPool.m?rev=38114&r1=38113&r2=38114&view=diff
==============================================================================
--- libs/sqlclient/trunk/SQLClientPool.m        (original)
+++ libs/sqlclient/trunk/SQLClientPool.m        Mon Oct 13 12:47:06 2014
@@ -49,6 +49,10 @@
 }
 @end
 
+@interface SQLClientPool (Adjust)
++ (void) _adjustPoolConnections: (int)n;
+@end
+
 @interface SQLClientPool (Private)
 - (void) _lock;
 - (void) _unlock;
@@ -106,6 +110,7 @@
       free(clients);
       free(used);
     }
+  [SQLClientPool _adjustPoolConnections: -count];
   [super dealloc];
 }
 
@@ -331,6 +336,7 @@
 
 - (void) setMax: (int)maxConnections min: (int)minConnections
 {
+  int   old;
   int   index;
 
   if (minConnections < 1) minConnections = 1;
@@ -338,6 +344,7 @@
   if (minConnections > maxConnections) minConnections = maxConnections;
 
   [self _lock];
+  old = max;
   if (maxConnections != max)
     {
       GSCache   *cache = nil;
@@ -379,8 +386,9 @@
               [c[index] setCache: cache];
             }
         }
-    }
-  max = maxConnections;
+      max = maxConnections;
+      [SQLClientPool _adjustPoolConnections: max - old];
+    }
   min = minConnections;
   [self _unlock];
 }


_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs

Reply via email to