MediaWiki  master
Wikimedia\Rdbms\LoadMonitor Class Reference

Basic DB load monitor with no external dependencies. More...

Inheritance diagram for Wikimedia\Rdbms\LoadMonitor:
Collaboration diagram for Wikimedia\Rdbms\LoadMonitor:

Public Member Functions

 __construct (ILoadBalancer $lb, BagOStuff $srvCache, WANObjectCache $wCache, array $options=[])
 
 getLagTimes (array $serverIndexes)
 Get an estimate of replication lag (in seconds) for each server. More...
 
 movingAverage ( $priorValue, $gaugeValue, float $delay, float $movAveRatio)
 Update a moving average for a gauge, accounting for the time delay since the last gauge. More...
 
 scaleLoads (array &$weightByServer)
 Perform load ratio adjustment before deciding which server to use. More...
 
 setLogger (LoggerInterface $logger)
 
 setMockTime (&$time)
 
 setStatsdDataFactory (StatsdDataFactoryInterface $statsFactory)
 Sets a StatsdDataFactory instance on the object. More...
 

Protected Member Functions

 computeServerStates (array $serverIndexes, $priorStates)
 
 getCurrentTime ()
 
 getServerStates (array $serverIndexes)
 
 getWeightScale ( $index, IDatabase $conn=null)
 
 isStateRefreshDue ( $priorAsOf, $priorGenDelay, $referenceTTL, $now)
 

Protected Attributes

ILoadBalancer $lb
 
LoggerInterface $logger
 
BagOStuff $srvCache
 
StatsdDataFactoryInterface $statsd
 
WANObjectCache $wanCache
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ __construct()

Wikimedia\Rdbms\LoadMonitor::__construct ( ILoadBalancer  $lb,
BagOStuff  $srvCache,
WANObjectCache  $wCache,
array  $options = [] 
)
Parameters
ILoadBalancer$lb
BagOStuff$srvCache
WANObjectCache$wCache
array$optionsAdditional parameters include:
  • movingAveRatio: maximum new gauge coefficient for moving averages when the new gauge is 1 second newer than the prior one [default: .54]
  • lagWarnThreshold: how many seconds of lag trigger warnings [default: 10]

Implements Wikimedia\Rdbms\ILoadMonitor.

Definition at line 83 of file LoadMonitor.php.

References Wikimedia\Rdbms\LoadMonitor\$lb, Wikimedia\Rdbms\LoadMonitor\$srvCache, and Wikimedia\Rdbms\LoadBalancer\MAX_LAG_DEFAULT.

Member Function Documentation

◆ computeServerStates()

Wikimedia\Rdbms\LoadMonitor::computeServerStates ( array  $serverIndexes,
  $priorStates 
)
protected
Parameters
array$serverIndexes
array | false$priorStates
Returns
array
Exceptions
DBAccessError

Definition at line 232 of file LoadMonitor.php.

References Wikimedia\Rdbms\LoadMonitor\getCurrentTime(), Wikimedia\Rdbms\LoadMonitor\getWeightScale(), and Wikimedia\Rdbms\LoadMonitor\movingAverage().

Referenced by Wikimedia\Rdbms\LoadMonitor\getServerStates().

◆ getCurrentTime()

Wikimedia\Rdbms\LoadMonitor::getCurrentTime ( )
protected
Returns
float UNIX timestamp

Definition at line 420 of file LoadMonitor.php.

Referenced by Wikimedia\Rdbms\LoadMonitor\computeServerStates(), and Wikimedia\Rdbms\LoadMonitor\getServerStates().

◆ getLagTimes()

Wikimedia\Rdbms\LoadMonitor::getLagTimes ( array  $serverIndexes)
final

Get an estimate of replication lag (in seconds) for each server.

Values may be "false" if replication is too broken to estimate

Parameters
int[]$serverIndexes
Returns
array Map of (server index => float|int|false)

Implements Wikimedia\Rdbms\ILoadMonitor.

Definition at line 118 of file LoadMonitor.php.

References Wikimedia\Rdbms\LoadMonitor\getServerStates().

◆ getServerStates()

Wikimedia\Rdbms\LoadMonitor::getServerStates ( array  $serverIndexes)
protected

◆ getWeightScale()

Wikimedia\Rdbms\LoadMonitor::getWeightScale (   $index,
IDatabase  $conn = null 
)
protected
Parameters
int$indexServer index
IDatabase | null$connConnection handle or null on connection failure
Returns
float
Since
1.28

Definition at line 351 of file LoadMonitor.php.

Referenced by Wikimedia\Rdbms\LoadMonitor\computeServerStates().

◆ isStateRefreshDue()

Wikimedia\Rdbms\LoadMonitor::isStateRefreshDue (   $priorAsOf,
  $priorGenDelay,
  $referenceTTL,
  $now 
)
protected
Parameters
float$priorAsOf
float$priorGenDelay
float$referenceTTL
float$now
Returns
bool

Definition at line 213 of file LoadMonitor.php.

Referenced by Wikimedia\Rdbms\LoadMonitor\getServerStates().

◆ movingAverage()

Wikimedia\Rdbms\LoadMonitor::movingAverage (   $priorValue,
  $gaugeValue,
float  $delay,
float  $movAveRatio 
)

Update a moving average for a gauge, accounting for the time delay since the last gauge.

Parameters
float | int | null$priorValuePrior moving average of value or null
float | int | null$gaugeValueNewly gauged value or null
float$delaySeconds between the new gauge and the prior one
float$movAveRatioNew gauge weight when it is 1 second newer than the prior one
Returns
float|false New moving average of value

Definition at line 364 of file LoadMonitor.php.

Referenced by Wikimedia\Rdbms\LoadMonitor\computeServerStates().

◆ scaleLoads()

Wikimedia\Rdbms\LoadMonitor::scaleLoads ( array &  $weightByServer)
final

Perform load ratio adjustment before deciding which server to use.

Parameters
int[]&$weightByServerMap of (server index => float weight)

Implements Wikimedia\Rdbms\ILoadMonitor.

Definition at line 104 of file LoadMonitor.php.

References Wikimedia\Rdbms\LoadMonitor\getServerStates().

◆ setLogger()

Wikimedia\Rdbms\LoadMonitor::setLogger ( LoggerInterface  $logger)

Definition at line 96 of file LoadMonitor.php.

References Wikimedia\Rdbms\LoadMonitor\$logger.

◆ setMockTime()

Wikimedia\Rdbms\LoadMonitor::setMockTime ( $time)
Parameters
float | null&$timeMock UNIX timestamp for testing

Definition at line 428 of file LoadMonitor.php.

◆ setStatsdDataFactory()

Wikimedia\Rdbms\LoadMonitor::setStatsdDataFactory ( StatsdDataFactoryInterface  $statsFactory)

Sets a StatsdDataFactory instance on the object.

Parameters
StatsdDataFactoryInterface$statsFactory
Returns
null

Implements StatsdAwareInterface.

Definition at line 100 of file LoadMonitor.php.

Member Data Documentation

◆ $lb

ILoadBalancer Wikimedia\Rdbms\LoadMonitor::$lb
protected

Definition at line 43 of file LoadMonitor.php.

Referenced by Wikimedia\Rdbms\LoadMonitor\__construct().

◆ $logger

LoggerInterface Wikimedia\Rdbms\LoadMonitor::$logger
protected

Definition at line 49 of file LoadMonitor.php.

Referenced by Wikimedia\Rdbms\LoadMonitor\setLogger().

◆ $srvCache

BagOStuff Wikimedia\Rdbms\LoadMonitor::$srvCache
protected

Definition at line 45 of file LoadMonitor.php.

Referenced by Wikimedia\Rdbms\LoadMonitor\__construct().

◆ $statsd

StatsdDataFactoryInterface Wikimedia\Rdbms\LoadMonitor::$statsd
protected

Definition at line 51 of file LoadMonitor.php.

◆ $wanCache

WANObjectCache Wikimedia\Rdbms\LoadMonitor::$wanCache
protected

Definition at line 47 of file LoadMonitor.php.


The documentation for this class was generated from the following file: