From: Aaron Schulz Date: Fri, 19 Sep 2014 18:48:09 +0000 (-0700) Subject: Limit active DB connections spawned in waitForAll() to one X-Git-Tag: 1.31.0-rc.0~13831^2 X-Git-Url: http://git.cyclocoop.org//%27%40script%40/%27?a=commitdiff_plain;h=cbdb81d1bc256caa87ac9e7fa857b8a800347905;p=lhc%2Fweb%2Fwiklou.git Limit active DB connections spawned in waitForAll() to one * If new connections are created, they will be closed before making the next ones now. Change-Id: I289d81ec00d3e1e313624e2a4c28a67bfb317feb --- diff --git a/includes/db/LoadBalancer.php b/includes/db/LoadBalancer.php index 8aa3bdbd4c..0ccbd933ae 100644 --- a/includes/db/LoadBalancer.php +++ b/includes/db/LoadBalancer.php @@ -394,7 +394,9 @@ class LoadBalancer { * @return bool */ protected function doWait( $index, $open = false, $timeout = null ) { - # Find a connection to wait on + $close = false; // close the connection afterwards + + # Find a connection to wait on, creating one if needed and allowed $conn = $this->getAnyOpenConnection( $index ); if ( !$conn ) { if ( !$open ) { @@ -408,6 +410,9 @@ class LoadBalancer { return false; } + // Avoid connection spam in waitForAll() when connections + // are made just for the sake of doing this lag check. + $close = true; } } @@ -418,13 +423,17 @@ class LoadBalancer { if ( $result == -1 || is_null( $result ) ) { # Timed out waiting for slave, use master instead wfDebug( __METHOD__ . ": Timed out waiting for slave #$index pos {$this->mWaitForPos}\n" ); - - return false; + $ok = false; } else { wfDebug( __METHOD__ . ": Done\n" ); + $ok = true; + } - return true; + if ( $close ) { + $this->closeConnection( $conn ); } + + return $ok; } /**