MediaWiki REL1_39
|
Basic DB load monitor with no external dependencies. More...
Public Member Functions | |
__construct (ILoadBalancer $lb, BagOStuff $srvCache, WANObjectCache $wCache, array $options=[]) | |
getLagTimes (array $serverIndexes, $domain) | |
Get an estimate of replication lag (in seconds) for each server. | |
scaleLoads (array &$weightByServer, $domain) | |
Perform load ratio adjustment before deciding which server to use. | |
setLogger (LoggerInterface $logger) | |
setMockTime (&$time) | |
setStatsdDataFactory (StatsdDataFactoryInterface $statsFactory) | |
Sets a StatsdDataFactory instance on the object. | |
Protected Member Functions | |
computeServerStates (array $serverIndexes, $domain, $priorStates) | |
getCurrentTime () | |
getNewScaleViaMovingAve ( $lastScale, $naiveScale, $movAveRatio) | |
Get the moving average weight scale given a naive and the last iteration value. | |
getServerStates (array $serverIndexes, $domain) | |
getWeightScale ( $index, IDatabase $conn=null) | |
Protected Attributes | |
ILoadBalancer | $lb |
LoggerInterface | $replLogger |
BagOStuff | $srvCache |
StatsdDataFactoryInterface | $statsd |
WANObjectCache | $wanCache |
Basic DB load monitor with no external dependencies.
Uses both server-local and shared caches for server state information.
The "domain" parameters are unused, though they might be used in the future. Therefore, at present, this assumes one channel of replication per server.
Definition at line 41 of file LoadMonitor.php.
Wikimedia\Rdbms\LoadMonitor::__construct | ( | ILoadBalancer | $lb, |
BagOStuff | $srvCache, | ||
WANObjectCache | $wCache, | ||
array | $options = [] ) |
ILoadBalancer | $lb | |
BagOStuff | $srvCache | |
WANObjectCache | $wCache | |
array | $options |
|
Implements Wikimedia\Rdbms\ILoadMonitor.
Reimplemented in Wikimedia\Rdbms\LoadMonitorMySQL.
Definition at line 81 of file LoadMonitor.php.
References Wikimedia\Rdbms\LoadMonitor\$lb, Wikimedia\Rdbms\LoadMonitor\$srvCache, and Wikimedia\Rdbms\LoadBalancer\MAX_LAG_DEFAULT.
|
protected |
array | $serverIndexes | |
string | false | $domain | |
array | false | $priorStates |
DBAccessError |
Definition at line 208 of file LoadMonitor.php.
References Wikimedia\Rdbms\ILoadBalancer\CONN_SILENCE_ERRORS, Wikimedia\Rdbms\ILoadBalancer\CONN_TRX_AUTOCOMMIT, Wikimedia\Rdbms\ILoadBalancer\DOMAIN_ANY, Wikimedia\Rdbms\LoadMonitor\getCurrentTime(), Wikimedia\Rdbms\LoadMonitor\getNewScaleViaMovingAve(), and Wikimedia\Rdbms\LoadMonitor\getWeightScale().
Referenced by Wikimedia\Rdbms\LoadMonitor\getServerStates().
|
protected |
Definition at line 407 of file LoadMonitor.php.
Referenced by Wikimedia\Rdbms\LoadMonitor\computeServerStates(), and Wikimedia\Rdbms\LoadMonitor\getServerStates().
|
final |
Get an estimate of replication lag (in seconds) for each server.
Values may be "false" if replication is too broken to estimate
int[] | $serverIndexes | |
string | $domain |
Implements Wikimedia\Rdbms\ILoadMonitor.
Definition at line 116 of file LoadMonitor.php.
References Wikimedia\Rdbms\LoadMonitor\getServerStates().
|
protected |
Get the moving average weight scale given a naive and the last iteration value.
One case of particular note is if a server totally cannot have its state queried. Ideally, the scale should be able to drop from 1.0 to a miniscule amount (say 0.001) fairly quickly. To get the time to reach 0.001, some calculations can be done:
SCALE = $naiveScale * $movAveRatio + $lastScale * (1 - $movAveRatio) SCALE = 0 * $movAveRatio + $lastScale * (1 - $movAveRatio) SCALE = $lastScale * (1 - $movAveRatio)
Given a starting weight scale of 1.0: 1.0 * (1 - $movAveRatio)^(# iterations) = 0.001 ceil( log<1 - $movAveRatio>(0.001) ) = (# iterations) t = (# iterations) * (POLL_PERIOD + SHARED_CACHE_TTL) t = (# iterations) * (1e3 * POLL_PERIOD_MS + SHARED_CACHE_TTL)
If $movAveRatio is 0.5, then: t = ceil( log<0.5>(0.01) ) * 1.5 = 7 * 1.5 = 10.5 seconds [for 1% scale] t = ceil( log<0.5>(0.001) ) * 1.5 = 10 * 1.5 = 15 seconds [for 0.1% scale]
If $movAveRatio is 0.8, then: t = ceil( log<0.2>(0.01) ) * 1.5 = 3 * 1.5 = 4.5 seconds [for 1% scale] t = ceil( log<0.2>(0.001) ) * 1.5 = 5 * 1.5 = 7.5 seconds [for 0.1% scale]
Use of connection failure rate can greatly speed this process up
float | $lastScale | Current moving average of scaling factors |
float | $naiveScale | New scaling factor |
float | $movAveRatio | Weight given to the new value |
Definition at line 368 of file LoadMonitor.php.
Referenced by Wikimedia\Rdbms\LoadMonitor\computeServerStates().
|
protected |
array | $serverIndexes | |
string | false | $domain |
DBAccessError |
Definition at line 126 of file LoadMonitor.php.
References Wikimedia\Rdbms\LoadMonitor\computeServerStates(), and Wikimedia\Rdbms\LoadMonitor\getCurrentTime().
Referenced by Wikimedia\Rdbms\LoadMonitor\getLagTimes(), and Wikimedia\Rdbms\LoadMonitor\scaleLoads().
|
protected |
int | $index | Server index |
IDatabase | null | $conn | Connection handle or null on connection failure |
Reimplemented in Wikimedia\Rdbms\LoadMonitorMySQL.
Definition at line 331 of file LoadMonitor.php.
Referenced by Wikimedia\Rdbms\LoadMonitor\computeServerStates().
|
final |
Perform load ratio adjustment before deciding which server to use.
int[] | &$weightByServer | Map of (server index => float weight) |
string | false | $domain |
Implements Wikimedia\Rdbms\ILoadMonitor.
Definition at line 102 of file LoadMonitor.php.
References Wikimedia\Rdbms\LoadMonitor\getServerStates().
Wikimedia\Rdbms\LoadMonitor::setLogger | ( | LoggerInterface | $logger | ) |
Definition at line 94 of file LoadMonitor.php.
Wikimedia\Rdbms\LoadMonitor::setMockTime | ( | & | $time | ) |
float | null | &$time | Mock UNIX timestamp for testing |
Definition at line 415 of file LoadMonitor.php.
Wikimedia\Rdbms\LoadMonitor::setStatsdDataFactory | ( | StatsdDataFactoryInterface | $statsFactory | ) |
Sets a StatsdDataFactory instance on the object.
StatsdDataFactoryInterface | $statsFactory |
Implements StatsdAwareInterface.
Definition at line 98 of file LoadMonitor.php.
|
protected |
Definition at line 43 of file LoadMonitor.php.
Referenced by Wikimedia\Rdbms\LoadMonitor\__construct(), and Wikimedia\Rdbms\LoadMonitorMySQL\__construct().
|
protected |
Definition at line 49 of file LoadMonitor.php.
|
protected |
Definition at line 45 of file LoadMonitor.php.
Referenced by Wikimedia\Rdbms\LoadMonitor\__construct(), and Wikimedia\Rdbms\LoadMonitorMySQL\__construct().
|
protected |
Definition at line 51 of file LoadMonitor.php.
|
protected |
Definition at line 47 of file LoadMonitor.php.