MediaWiki REL1_37
|
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) | |
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 |
WANObjectCache | $wanCache |
Private Member Functions | |
acquireServerStatesLoopGuard () | |
getPlaceholderServerStates (array $serverIndexes) | |
getStatesCacheKey ( $cache, array $serverIndexes) | |
Private Attributes | |
int | $lagWarnThreshold |
Amount of replication lag in seconds before warnings are logged. | |
float | $movingAveRatio |
Moving average ratio (e.g. | |
bool | $serverStatesKeyLocked = false |
Whether the "server states" cache key is in the process of being updated. | |
float null | $wallClockOverride |
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 79 of file LoadMonitor.php.
References Wikimedia\Rdbms\LoadMonitor\$lb, Wikimedia\Rdbms\LoadMonitor\$srvCache, and Wikimedia\Rdbms\LoadBalancer\MAX_LAG_DEFAULT.
|
private |
Definition at line 376 of file LoadMonitor.php.
Referenced by Wikimedia\Rdbms\LoadMonitor\getServerStates().
|
protected |
array | $serverIndexes | |
string | bool | $domain | |
array | false | $priorStates |
DBAccessError |
Definition at line 201 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(), Wikimedia\Rdbms\LoadMonitor\getPlaceholderServerStates(), and Wikimedia\Rdbms\LoadMonitor\getWeightScale().
Referenced by Wikimedia\Rdbms\LoadMonitor\getServerStates().
|
protected |
Definition at line 392 of file LoadMonitor.php.
Referenced by Wikimedia\Rdbms\LoadMonitor\computeServerStates(), Wikimedia\Rdbms\LoadMonitor\getPlaceholderServerStates(), 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 109 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 353 of file LoadMonitor.php.
Referenced by Wikimedia\Rdbms\LoadMonitor\computeServerStates().
|
private |
int[] | $serverIndexes |
Definition at line 302 of file LoadMonitor.php.
References Wikimedia\Rdbms\LoadMonitor\getCurrentTime().
Referenced by Wikimedia\Rdbms\LoadMonitor\computeServerStates(), and Wikimedia\Rdbms\LoadMonitor\getServerStates().
|
protected |
array | $serverIndexes | |
string | bool | $domain |
DBAccessError |
Definition at line 119 of file LoadMonitor.php.
References Wikimedia\Rdbms\LoadMonitor\acquireServerStatesLoopGuard(), Wikimedia\Rdbms\LoadMonitor\computeServerStates(), Wikimedia\Rdbms\LoadMonitor\getCurrentTime(), Wikimedia\Rdbms\LoadMonitor\getPlaceholderServerStates(), and Wikimedia\Rdbms\LoadMonitor\getStatesCacheKey().
Referenced by Wikimedia\Rdbms\LoadMonitor\getLagTimes(), and Wikimedia\Rdbms\LoadMonitor\scaleLoads().
|
private |
WANObjectCache | BagOStuff | $cache | |
array | $serverIndexes |
Definition at line 362 of file LoadMonitor.php.
References $cache.
Referenced by Wikimedia\Rdbms\LoadMonitor\getServerStates().
|
protected |
int | $index | Server index |
IDatabase | null | $conn | Connection handle or null on connection failure |
Reimplemented in Wikimedia\Rdbms\LoadMonitorMySQL.
Definition at line 316 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 | bool | $domain |
Implements Wikimedia\Rdbms\ILoadMonitor.
Definition at line 95 of file LoadMonitor.php.
References Wikimedia\Rdbms\LoadMonitor\getServerStates().
Wikimedia\Rdbms\LoadMonitor::setLogger | ( | LoggerInterface | $logger | ) |
Definition at line 91 of file LoadMonitor.php.
Wikimedia\Rdbms\LoadMonitor::setMockTime | ( | & | $time | ) |
float | null | &$time | Mock UNIX timestamp for testing |
Definition at line 400 of file LoadMonitor.php.
|
private |
Amount of replication lag in seconds before warnings are logged.
Definition at line 54 of file LoadMonitor.php.
|
protected |
Definition at line 43 of file LoadMonitor.php.
Referenced by Wikimedia\Rdbms\LoadMonitor\__construct(), and Wikimedia\Rdbms\LoadMonitorMySQL\__construct().
|
private |
Moving average ratio (e.g.
0.1 for 10% weight to new weight)
Definition at line 52 of file LoadMonitor.php.
|
protected |
Definition at line 49 of file LoadMonitor.php.
|
private |
Whether the "server states" cache key is in the process of being updated.
Definition at line 60 of file LoadMonitor.php.
|
protected |
Definition at line 45 of file LoadMonitor.php.
Referenced by Wikimedia\Rdbms\LoadMonitor\__construct(), and Wikimedia\Rdbms\LoadMonitorMySQL\__construct().
|
private |
Definition at line 57 of file LoadMonitor.php.
|
protected |
Definition at line 47 of file LoadMonitor.php.