Avoid pool fragmentation in RedisConnectionPool.
authorAaron Schulz <aschulz@wikimedia.org>
Thu, 21 Feb 2013 22:03:26 +0000 (14:03 -0800)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 26 Feb 2013 20:47:27 +0000 (20:47 +0000)
* Avoid fragmenting the client pools due to "poolSize" differences.
  Instead that config parameter does not affect the pool something uses,
  but the pool used will grow to fit the pool size of anything using it.

Change-Id: Ibc9db7cfc277824b1acde5e6fbf1db0ed296cb41

includes/clientpool/RedisConnectionPool.php

index eace85a..bb8b77f 100644 (file)
@@ -98,12 +98,20 @@ class RedisConnectionPool {
         * @return RedisConnectionPool
         */
        public static function singleton( array $options ) {
-               ksort( $options ); // normalize
-               $id = sha1( serialize( $options ) );
+               // Map the options to a unique hash...
+               $poolOptions = $options;
+               unset( $poolOptions['poolSize'] ); // avoid pool fragmentation
+               ksort( $poolOptions ); // normalize to avoid pool fragmentation
+               $id = sha1( serialize( $poolOptions ) );
+               // Initialize the object at the hash as needed...
                if ( !isset( self::$instances[$id] ) ) {
                        self::$instances[$id] = new self( $options );
                        wfDebug( "Creating a new " . __CLASS__ . " instance with id $id." );
                }
+               // Simply grow the pool size if the existing one is too small
+               $psize = isset( $options['poolSize'] ) ? $options['poolSize'] : 1; // size requested
+               self::$instances[$id]->poolSize = max( $psize, self::$instances[$id]->poolSize );
+
                return self::$instances[$id];
        }