Removed "poolSize" option from RedisConnectionPool.
* The size is now automatically based on the number of servers. Change-Id: I6ea53378c9c8254e8556c0a1e4efe64fd71ba356
This commit is contained in:
parent
5cfcb3053d
commit
646051d36d
1 changed files with 6 additions and 18 deletions
|
|
@ -40,7 +40,6 @@ class RedisConnectionPool {
|
||||||
protected $connectTimeout; // string; connection timeout
|
protected $connectTimeout; // string; connection timeout
|
||||||
protected $persistent; // bool; whether connections persist
|
protected $persistent; // bool; whether connections persist
|
||||||
protected $password; // string; plaintext auth password
|
protected $password; // string; plaintext auth password
|
||||||
protected $poolSize; // integer; maximum number of idle connections
|
|
||||||
protected $serializer; // integer; the serializer to use (Redis::SERIALIZER_*)
|
protected $serializer; // integer; the serializer to use (Redis::SERIALIZER_*)
|
||||||
|
|
||||||
protected $idlePoolSize = 0; // integer; current idle pool size
|
protected $idlePoolSize = 0; // integer; current idle pool size
|
||||||
|
|
@ -61,7 +60,6 @@ class RedisConnectionPool {
|
||||||
* Optional, default is 1 second.
|
* Optional, default is 1 second.
|
||||||
* - persistent : Set this to true to allow connections to persist across
|
* - persistent : Set this to true to allow connections to persist across
|
||||||
* multiple web requests. False by default.
|
* multiple web requests. False by default.
|
||||||
* - poolSize : Maximim number of idle connections. Default is 5.
|
|
||||||
* - password : The authentication password, will be sent to Redis in clear text.
|
* - password : The authentication password, will be sent to Redis in clear text.
|
||||||
* Optional, if it is unspecified, no AUTH command will be sent.
|
* Optional, if it is unspecified, no AUTH command will be sent.
|
||||||
* - serializer : Set to "php" or "igbinary". Default is "php".
|
* - serializer : Set to "php" or "igbinary". Default is "php".
|
||||||
|
|
@ -75,7 +73,6 @@ class RedisConnectionPool {
|
||||||
$this->connectTimeout = $options['connectTimeout'];
|
$this->connectTimeout = $options['connectTimeout'];
|
||||||
$this->persistent = $options['persistent'];
|
$this->persistent = $options['persistent'];
|
||||||
$this->password = $options['password'];
|
$this->password = $options['password'];
|
||||||
$this->poolSize = $options['poolSize'];
|
|
||||||
if ( !isset( $options['serializer'] ) || $options['serializer'] === 'php' ) {
|
if ( !isset( $options['serializer'] ) || $options['serializer'] === 'php' ) {
|
||||||
$this->serializer = Redis::SERIALIZER_PHP;
|
$this->serializer = Redis::SERIALIZER_PHP;
|
||||||
} elseif ( $options['serializer'] === 'igbinary' ) {
|
} elseif ( $options['serializer'] === 'igbinary' ) {
|
||||||
|
|
@ -99,9 +96,6 @@ class RedisConnectionPool {
|
||||||
if ( !isset( $options['password'] ) ) {
|
if ( !isset( $options['password'] ) ) {
|
||||||
$options['password'] = '';
|
$options['password'] = '';
|
||||||
}
|
}
|
||||||
if ( !isset( $options['poolSize'] ) ) {
|
|
||||||
$options['poolSize'] = 1;
|
|
||||||
}
|
|
||||||
return $options;
|
return $options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -112,19 +106,13 @@ class RedisConnectionPool {
|
||||||
public static function singleton( array $options ) {
|
public static function singleton( array $options ) {
|
||||||
$options = self::applyDefaultConfig( $options );
|
$options = self::applyDefaultConfig( $options );
|
||||||
// Map the options to a unique hash...
|
// Map the options to a unique hash...
|
||||||
$poolOptions = $options;
|
ksort( $options ); // normalize to avoid pool fragmentation
|
||||||
unset( $poolOptions['poolSize'] ); // avoid pool fragmentation
|
$id = sha1( serialize( $options ) );
|
||||||
ksort( $poolOptions ); // normalize to avoid pool fragmentation
|
|
||||||
$id = sha1( serialize( $poolOptions ) );
|
|
||||||
// Initialize the object at the hash as needed...
|
// Initialize the object at the hash as needed...
|
||||||
if ( !isset( self::$instances[$id] ) ) {
|
if ( !isset( self::$instances[$id] ) ) {
|
||||||
self::$instances[$id] = new self( $options );
|
self::$instances[$id] = new self( $options );
|
||||||
wfDebug( "Creating a new " . __CLASS__ . " instance with id $id." );
|
wfDebug( "Creating a new " . __CLASS__ . " instance with id $id." );
|
||||||
}
|
}
|
||||||
// Simply grow the pool size if the existing one is too small
|
|
||||||
$psize = $options['poolSize']; // size requested
|
|
||||||
self::$instances[$id]->poolSize = max( $psize, self::$instances[$id]->poolSize );
|
|
||||||
|
|
||||||
return self::$instances[$id];
|
return self::$instances[$id];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -244,16 +232,16 @@ class RedisConnectionPool {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function closeExcessIdleConections() {
|
protected function closeExcessIdleConections() {
|
||||||
if ( $this->idlePoolSize <= $this->poolSize ) {
|
if ( $this->idlePoolSize <= count( $this->connections ) ) {
|
||||||
return; // nothing to do
|
return; // nothing to do (no more connections than servers)
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ( $this->connections as $server => &$serverConnections ) {
|
foreach ( $this->connections as $server => &$serverConnections ) {
|
||||||
foreach ( $serverConnections as $key => &$connection ) {
|
foreach ( $serverConnections as $key => &$connection ) {
|
||||||
if ( $connection['free'] ) {
|
if ( $connection['free'] ) {
|
||||||
unset( $serverConnections[$key] );
|
unset( $serverConnections[$key] );
|
||||||
if ( --$this->idlePoolSize <= $this->poolSize ) {
|
if ( --$this->idlePoolSize <= count( $this->connections ) ) {
|
||||||
return; // done
|
return; // done (no more connections than servers)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue