From: Aaron Schulz Date: Thu, 21 Feb 2013 22:03:26 +0000 (-0800) Subject: Avoid pool fragmentation in RedisConnectionPool. X-Git-Tag: 1.31.0-rc.0~20558 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22auteur_infos%22%2C%20%22id_auteur=%24id%22%29%20.%20%22?a=commitdiff_plain;h=7e6ad48641e9fbf3b9650112d0d9ea463507d0f9;p=lhc%2Fweb%2Fwiklou.git 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 --- 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]; }