diff options
author | jenkins-bot <jenkins-bot@gerrit.wikimedia.org> | 2014-07-11 18:02:10 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@wikimedia.org> | 2014-07-11 18:02:10 +0000 |
commit | b3c307518a8dfd8a38267e17edbc8342822c2f45 (patch) | |
tree | 57fce77dee672fae9c6fb07e4362507228afc282 /includes/db/LoadBalancer.php | |
parent | 05876fbbfcbdce46faebd390eade054269060637 (diff) | |
parent | f9ddcb04539398dc7432aacd456e1ba9ed0b64a6 (diff) | |
download | mediawikicore-b3c307518a8dfd8a38267e17edbc8342822c2f45.tar.gz mediawikicore-b3c307518a8dfd8a38267e17edbc8342822c2f45.zip |
Merge "Made getMaxLag() use caching to reduce connection spam"
Diffstat (limited to 'includes/db/LoadBalancer.php')
-rw-r--r-- | includes/db/LoadBalancer.php | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/includes/db/LoadBalancer.php b/includes/db/LoadBalancer.php index 0c4188ceda46..53532880d13a 100644 --- a/includes/db/LoadBalancer.php +++ b/includes/db/LoadBalancer.php @@ -1048,7 +1048,18 @@ class LoadBalancer { $maxLag = -1; $host = ''; $maxIndex = 0; - if ( $this->getServerCount() > 1 ) { // no replication = no lag + + if ( $this->getServerCount() <= 1 ) { // no replication = no lag + return array( $host, $maxLag, $maxIndex ); + } + + // Try to get the max lag info from the server cache + $key = 'loadbalancer:maxlag:cluster:' . $this->mServers[0]['host']; + $cache = ObjectCache::newAccelerator( array(), 'hash' ); + $maxLagInfo = $cache->get( $key ); // (host, lag, index) + + // Fallback to connecting to each slave and getting the lag + if ( !$maxLagInfo ) { foreach ( $this->mServers as $i => $conn ) { if ( $i == $this->getWriterIndex() ) { continue; // nothing to check @@ -1070,9 +1081,11 @@ class LoadBalancer { $maxIndex = $i; } } + $maxLagInfo = array( $host, $maxLag, $maxIndex ); + $cache->set( $key, $maxLagInfo, 5 ); } - return array( $host, $maxLag, $maxIndex ); + return $maxLagInfo; } /** |