Removed unused postConnectionBackoff() from LoadMonitor
* This setting proved to be not terrible useful Change-Id: I58b18947ff0edb8937229d0f130d7d10e846125e
This commit is contained in:
parent
717f428d64
commit
b3c9653090
4 changed files with 48 additions and 127 deletions
|
|
@ -31,6 +31,7 @@ production.
|
||||||
* $wgPasswordSenderName has been deprecated. To set a custom mailer name,
|
* $wgPasswordSenderName has been deprecated. To set a custom mailer name,
|
||||||
the system message 'emailsender' should be modified (default: "{{SITENAME}}").
|
the system message 'emailsender' should be modified (default: "{{SITENAME}}").
|
||||||
* $wgDBAhandler was removed as the only class using it was also removed
|
* $wgDBAhandler was removed as the only class using it was also removed
|
||||||
|
* The 'max threads' setting was removed from $wgDBservers.
|
||||||
|
|
||||||
=== New features in 1.23 ===
|
=== New features in 1.23 ===
|
||||||
* ResourceLoader can utilize the Web Storage API to cache modules client-side.
|
* ResourceLoader can utilize the Web Storage API to cache modules client-side.
|
||||||
|
|
|
||||||
|
|
@ -1654,7 +1654,6 @@ $wgSharedTables = array( 'user', 'user_properties' );
|
||||||
* if available
|
* if available
|
||||||
*
|
*
|
||||||
* - max lag: (optional) Maximum replication lag before a slave will taken out of rotation
|
* - max lag: (optional) Maximum replication lag before a slave will taken out of rotation
|
||||||
* - max threads: (optional) Maximum number of running threads
|
|
||||||
*
|
*
|
||||||
* These and any other user-defined properties will be assigned to the mLBInfo member
|
* These and any other user-defined properties will be assigned to the mLBInfo member
|
||||||
* variable of the Database object.
|
* variable of the Database object.
|
||||||
|
|
|
||||||
|
|
@ -188,7 +188,7 @@ class LoadBalancer {
|
||||||
* @return bool|int|string
|
* @return bool|int|string
|
||||||
*/
|
*/
|
||||||
function getReaderIndex( $group = false, $wiki = false ) {
|
function getReaderIndex( $group = false, $wiki = false ) {
|
||||||
global $wgReadOnly, $wgDBClusterTimeout, $wgDBAvgStatusPoll, $wgDBtype;
|
global $wgReadOnly, $wgDBtype;
|
||||||
|
|
||||||
# @todo FIXME: For now, only go through all this for mysql databases
|
# @todo FIXME: For now, only go through all this for mysql databases
|
||||||
if ( $wgDBtype != 'mysql' ) {
|
if ( $wgDBtype != 'mysql' ) {
|
||||||
|
|
@ -198,18 +198,13 @@ class LoadBalancer {
|
||||||
if ( count( $this->mServers ) == 1 ) {
|
if ( count( $this->mServers ) == 1 ) {
|
||||||
# Skip the load balancing if there's only one server
|
# Skip the load balancing if there's only one server
|
||||||
return 0;
|
return 0;
|
||||||
} elseif ( $group === false and $this->mReadIndex >= 0 ) {
|
} elseif ( $group === false && $this->mReadIndex >= 0 ) {
|
||||||
# Shortcut if generic reader exists already
|
# Shortcut if generic reader exists already
|
||||||
return $this->mReadIndex;
|
return $this->mReadIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
wfProfileIn( __METHOD__ );
|
wfProfileIn( __METHOD__ );
|
||||||
|
|
||||||
$totalElapsed = 0;
|
|
||||||
|
|
||||||
# convert from seconds to microseconds
|
|
||||||
$timeout = $wgDBClusterTimeout * 1e6;
|
|
||||||
|
|
||||||
# Find the relevant load array
|
# Find the relevant load array
|
||||||
if ( $group !== false ) {
|
if ( $group !== false ) {
|
||||||
if ( isset( $this->mGroupLoads[$group] ) ) {
|
if ( isset( $this->mGroupLoads[$group] ) ) {
|
||||||
|
|
@ -225,7 +220,7 @@ class LoadBalancer {
|
||||||
$nonErrorLoads = $this->mLoads;
|
$nonErrorLoads = $this->mLoads;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !$nonErrorLoads ) {
|
if ( !count( $nonErrorLoads ) ) {
|
||||||
wfProfileOut( __METHOD__ );
|
wfProfileOut( __METHOD__ );
|
||||||
throw new MWException( "Empty server array given to LoadBalancer" );
|
throw new MWException( "Empty server array given to LoadBalancer" );
|
||||||
}
|
}
|
||||||
|
|
@ -235,93 +230,60 @@ class LoadBalancer {
|
||||||
|
|
||||||
$laggedSlaveMode = false;
|
$laggedSlaveMode = false;
|
||||||
|
|
||||||
|
# No server found yet
|
||||||
|
$i = false;
|
||||||
# First try quickly looking through the available servers for a server that
|
# First try quickly looking through the available servers for a server that
|
||||||
# meets our criteria
|
# meets our criteria
|
||||||
do {
|
$currentLoads = $nonErrorLoads;
|
||||||
$totalThreadsConnected = 0;
|
while ( count( $currentLoads ) ) {
|
||||||
$overloadedServers = 0;
|
if ( $wgReadOnly || $this->mAllowLagged || $laggedSlaveMode ) {
|
||||||
$currentLoads = $nonErrorLoads;
|
$i = ArrayUtils::pickRandom( $currentLoads );
|
||||||
while ( count( $currentLoads ) ) {
|
} else {
|
||||||
if ( $wgReadOnly || $this->mAllowLagged || $laggedSlaveMode ) {
|
$i = $this->getRandomNonLagged( $currentLoads, $wiki );
|
||||||
|
if ( $i === false && count( $currentLoads ) != 0 ) {
|
||||||
|
# All slaves lagged. Switch to read-only mode
|
||||||
|
wfDebugLog( 'replication', "All slaves lagged. Switch to read-only mode\n" );
|
||||||
|
$wgReadOnly = 'The database has been automatically locked ' .
|
||||||
|
'while the slave database servers catch up to the master';
|
||||||
$i = ArrayUtils::pickRandom( $currentLoads );
|
$i = ArrayUtils::pickRandom( $currentLoads );
|
||||||
} else {
|
$laggedSlaveMode = true;
|
||||||
$i = $this->getRandomNonLagged( $currentLoads, $wiki );
|
|
||||||
if ( $i === false && count( $currentLoads ) != 0 ) {
|
|
||||||
# All slaves lagged. Switch to read-only mode
|
|
||||||
wfDebugLog( 'replication', "All slaves lagged. Switch to read-only mode\n" );
|
|
||||||
$wgReadOnly = 'The database has been automatically locked ' .
|
|
||||||
'while the slave database servers catch up to the master';
|
|
||||||
$i = ArrayUtils::pickRandom( $currentLoads );
|
|
||||||
$laggedSlaveMode = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( $i === false ) {
|
|
||||||
# pickRandom() returned false
|
|
||||||
# This is permanent and means the configuration or the load monitor
|
|
||||||
# wants us to return false.
|
|
||||||
wfDebugLog( 'connect', __METHOD__ . ": pickRandom() returned false\n" );
|
|
||||||
wfProfileOut( __METHOD__ );
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
wfDebugLog( 'connect', __METHOD__ . ": Using reader #$i: {$this->mServers[$i]['host']}...\n" );
|
|
||||||
$conn = $this->openConnection( $i, $wiki );
|
|
||||||
|
|
||||||
if ( !$conn ) {
|
|
||||||
wfDebugLog( 'connect', __METHOD__ . ": Failed connecting to $i/$wiki\n" );
|
|
||||||
unset( $nonErrorLoads[$i] );
|
|
||||||
unset( $currentLoads[$i] );
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Perform post-connection backoff
|
|
||||||
$threshold = isset( $this->mServers[$i]['max threads'] )
|
|
||||||
? $this->mServers[$i]['max threads'] : 0;
|
|
||||||
$backoff = $this->getLoadMonitor()->postConnectionBackoff( $conn, $threshold );
|
|
||||||
|
|
||||||
// Decrement reference counter, we are finished with this connection.
|
|
||||||
// It will be incremented for the caller later.
|
|
||||||
if ( $wiki !== false ) {
|
|
||||||
$this->reuseConnection( $conn );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( $backoff ) {
|
|
||||||
# Post-connection overload, don't use this server for now
|
|
||||||
$totalThreadsConnected += $backoff;
|
|
||||||
$overloadedServers++;
|
|
||||||
unset( $currentLoads[$i] );
|
|
||||||
} else {
|
|
||||||
# Return this server
|
|
||||||
break 2;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# No server found yet
|
if ( $i === false ) {
|
||||||
$i = false;
|
# pickRandom() returned false
|
||||||
|
# This is permanent and means the configuration or the load monitor
|
||||||
|
# wants us to return false.
|
||||||
|
wfDebugLog( 'connect', __METHOD__ . ": pickRandom() returned false\n" );
|
||||||
|
wfProfileOut( __METHOD__ );
|
||||||
|
|
||||||
# If all servers were down, quit now
|
return false;
|
||||||
if ( !count( $nonErrorLoads ) ) {
|
|
||||||
wfDebugLog( 'connect', "All servers down\n" );
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Some servers must have been overloaded
|
wfDebugLog( 'connect', __METHOD__ .
|
||||||
if ( $overloadedServers == 0 ) {
|
": Using reader #$i: {$this->mServers[$i]['host']}...\n" );
|
||||||
throw new MWException( __METHOD__ . ": unexpectedly found no overloaded servers" );
|
|
||||||
}
|
|
||||||
# Back off for a while
|
|
||||||
# Scale the sleep time by the number of connected threads, to produce a
|
|
||||||
# roughly constant global poll rate
|
|
||||||
$avgThreads = $totalThreadsConnected / $overloadedServers;
|
|
||||||
$totalElapsed += $this->sleep( $wgDBAvgStatusPoll * $avgThreads );
|
|
||||||
} while ( $totalElapsed < $timeout );
|
|
||||||
|
|
||||||
if ( $totalElapsed >= $timeout ) {
|
$conn = $this->openConnection( $i, $wiki );
|
||||||
wfDebugLog( 'connect', "All servers busy\n" );
|
if ( !$conn ) {
|
||||||
$this->mErrorConnection = false;
|
wfDebugLog( 'connect', __METHOD__ . ": Failed connecting to $i/$wiki\n" );
|
||||||
$this->mLastError = 'All servers busy';
|
unset( $nonErrorLoads[$i] );
|
||||||
|
unset( $currentLoads[$i] );
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Decrement reference counter, we are finished with this connection.
|
||||||
|
// It will be incremented for the caller later.
|
||||||
|
if ( $wiki !== false ) {
|
||||||
|
$this->reuseConnection( $conn );
|
||||||
|
}
|
||||||
|
|
||||||
|
# Return this server
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
# If all servers were down, quit now
|
||||||
|
if ( !count( $nonErrorLoads ) ) {
|
||||||
|
wfDebugLog( 'connect', "All servers down\n" );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $i !== false ) {
|
if ( $i !== false ) {
|
||||||
|
|
|
||||||
|
|
@ -42,24 +42,6 @@ interface LoadMonitor {
|
||||||
*/
|
*/
|
||||||
function scaleLoads( &$loads, $group = false, $wiki = false );
|
function scaleLoads( &$loads, $group = false, $wiki = false );
|
||||||
|
|
||||||
/**
|
|
||||||
* Perform post-connection backoff.
|
|
||||||
*
|
|
||||||
* If the connection is in overload, this should return a backoff factor
|
|
||||||
* which will be used to control polling time. The number of threads
|
|
||||||
* connected is a good measure.
|
|
||||||
*
|
|
||||||
* If there is no overload, zero can be returned.
|
|
||||||
*
|
|
||||||
* A threshold thread count is given, the concrete class may compare this
|
|
||||||
* to the running thread count. The threshold may be false, which indicates
|
|
||||||
* that the sysadmin has not configured this feature.
|
|
||||||
*
|
|
||||||
* @param DatabaseBase $conn
|
|
||||||
* @param float $threshold
|
|
||||||
*/
|
|
||||||
function postConnectionBackoff( $conn, $threshold );
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return an estimate of replication lag for each server
|
* Return an estimate of replication lag for each server
|
||||||
*
|
*
|
||||||
|
|
@ -78,9 +60,6 @@ class LoadMonitorNull implements LoadMonitor {
|
||||||
function scaleLoads( &$loads, $group = false, $wiki = false ) {
|
function scaleLoads( &$loads, $group = false, $wiki = false ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function postConnectionBackoff( $conn, $threshold ) {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $serverIndexes
|
* @param array $serverIndexes
|
||||||
* @param string $wiki
|
* @param string $wiki
|
||||||
|
|
@ -188,24 +167,4 @@ class LoadMonitorMySQL implements LoadMonitor {
|
||||||
|
|
||||||
return $times;
|
return $times;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param DatabaseBase|DatabaseMySQLBase $conn
|
|
||||||
* @param int $threshold
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
function postConnectionBackoff( $conn, $threshold ) {
|
|
||||||
if ( !$threshold ) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
$status = $conn->getMysqlStatus( "Thread%" );
|
|
||||||
if ( $status['Threads_running'] > $threshold ) {
|
|
||||||
$server = $conn->getProperty( 'mServer' );
|
|
||||||
wfLogDBError( "LB backoff from $server - Threads_running = {$status['Threads_running']}\n" );
|
|
||||||
|
|
||||||
return $status['Threads_connected'];
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue