Tim Starling has submitted this change and it was merged.

Change subject: Avoid pool fragmentation in RedisConnectionPool.
......................................................................


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
---
M includes/clientpool/RedisConnectionPool.php
1 file changed, 10 insertions(+), 2 deletions(-)

Approvals:
  Tim Starling: Verified; Looks good to me, approved
  jenkins-bot: Checked



diff --git a/includes/clientpool/RedisConnectionPool.php 
b/includes/clientpool/RedisConnectionPool.php
index eace85a..bb8b77f 100644
--- a/includes/clientpool/RedisConnectionPool.php
+++ b/includes/clientpool/RedisConnectionPool.php
@@ -98,12 +98,20 @@
         * @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];
        }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/50291
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ibc9db7cfc277824b1acde5e6fbf1db0ed296cb41
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org>
Gerrit-Reviewer: Tim Starling <tstarl...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to