From 7e6ad48641e9fbf3b9650112d0d9ea463507d0f9 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Thu, 21 Feb 2013 14:03:26 -0800 Subject: [PATCH] Avoid pool fragmentation in RedisConnectionPool. * 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 | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/includes/clientpool/RedisConnectionPool.php b/includes/clientpool/RedisConnectionPool.php index eace85ad71..bb8b77f965 100644 --- a/includes/clientpool/RedisConnectionPool.php +++ b/includes/clientpool/RedisConnectionPool.php @@ -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]; } -- 2.20.1