From 845e5b24c4a631a63096fe2cf8f9d38a92bb6787 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Mon, 10 Feb 2014 19:03:05 -0800 Subject: [PATCH] Cleanups to LoadMonitor * Use ProfileSection * Removed redundant doc blocks * Added method visibility Change-Id: I76cd666c28b8bea7d5997a9f2b7d1c39539f7c5e --- includes/db/LoadMonitor.php | 43 ++++++++++--------------------------- 1 file changed, 11 insertions(+), 32 deletions(-) diff --git a/includes/db/LoadMonitor.php b/includes/db/LoadMonitor.php index b6ba4f2588..fa2dd99ff8 100644 --- a/includes/db/LoadMonitor.php +++ b/includes/db/LoadMonitor.php @@ -32,7 +32,7 @@ interface LoadMonitor { * * @param LoadBalancer $parent */ - function __construct( $parent ); + public function __construct( $parent ); /** * Perform pre-connection load ratio adjustment. @@ -40,7 +40,7 @@ interface LoadMonitor { * @param string|bool $group The selected query group. Default: false * @param string|bool $wiki Default: false */ - function scaleLoads( &$loads, $group = false, $wiki = false ); + public function scaleLoads( &$loads, $group = false, $wiki = false ); /** * Return an estimate of replication lag for each server @@ -50,22 +50,17 @@ interface LoadMonitor { * * @return array */ - function getLagTimes( $serverIndexes, $wiki ); + public function getLagTimes( $serverIndexes, $wiki ); } class LoadMonitorNull implements LoadMonitor { - function __construct( $parent ) { + public function __construct( $parent ) { } - function scaleLoads( &$loads, $group = false, $wiki = false ) { + public function scaleLoads( &$loads, $group = false, $wiki = false ) { } - /** - * @param array $serverIndexes - * @param string $wiki - * @return array - */ - function getLagTimes( $serverIndexes, $wiki ) { + public function getLagTimes( $serverIndexes, $wiki ) { return array_fill_keys( $serverIndexes, 0 ); } } @@ -80,33 +75,21 @@ class LoadMonitorMySQL implements LoadMonitor { /** @var LoadBalancer */ public $parent; - /** - * @param LoadBalancer $parent - */ - function __construct( $parent ) { + public function __construct( $parent ) { $this->parent = $parent; } - /** - * @param array $loads - * @param bool $group - * @param bool $wiki - */ - function scaleLoads( &$loads, $group = false, $wiki = false ) { + public function scaleLoads( &$loads, $group = false, $wiki = false ) { } - /** - * @param array $serverIndexes - * @param string $wiki - * @return array - */ - function getLagTimes( $serverIndexes, $wiki ) { + public function getLagTimes( $serverIndexes, $wiki ) { if ( count( $serverIndexes ) == 1 && reset( $serverIndexes ) == 0 ) { // Single server only, just return zero without caching return array( 0 => 0 ); } - wfProfileIn( __METHOD__ ); + $section = new ProfileSection( __METHOD__ ); + $expiry = 5; $requestRate = 10; @@ -124,7 +107,6 @@ class LoadMonitorMySQL implements LoadMonitor { $chance = max( 0, ( $expiry - $elapsed ) * $requestRate ); if ( mt_rand( 0, $chance ) != 0 ) { unset( $times['timestamp'] ); // hide from caller - wfProfileOut( __METHOD__ ); return $times; } @@ -142,7 +124,6 @@ class LoadMonitorMySQL implements LoadMonitor { } elseif ( is_array( $times ) ) { # Could not acquire lock but an old cache exists, so use it unset( $times['timestamp'] ); // hide from caller - wfProfileOut( __METHOD__ ); return $times; } @@ -163,8 +144,6 @@ class LoadMonitorMySQL implements LoadMonitor { $wgMemc->set( $memcKey, $times, $expiry + 10 ); unset( $times['timestamp'] ); // hide from caller - wfProfileOut( __METHOD__ ); - return $times; } } -- 2.20.1