MediaWiki master
Wikimedia\Rdbms\LoadMonitor Class Reference

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

Inherits Wikimedia\Rdbms\ILoadMonitor.

Inherited by Wikimedia\Rdbms\LoadMonitorNull.

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 the specified servers.
 
 getServerStates (array $serverIndexes)
 Get a server gauge map for the specified servers.
 
 movingAverage ( $priorValue, $gaugeValue, float $delay, float $movAveRatio)
 Update a moving average for a gauge, accounting for the time delay since the last gauge.
 
 scaleLoads (array &$weightByServer)
 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

 computeServerState (int $i, ?array $priorState)
 
 getCurrentTime ()
 
 getWeightScale (array $state)
 
 isStateFresh ( $state, $now)
 
 isStateRefreshDue ( $priorAsOf, $priorGenDelay, $referenceTTL, $now)
 
 makeStateKey (IStoreKeyEncoder $cache, int $i)
 
 newInitialServerState ()
 

Protected Attributes

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

Additional Inherited Members

- Public Attributes inherited from Wikimedia\Rdbms\ILoadMonitor
const STATE_AS_OF = 'time'
 
const STATE_GEN_DELAY = 'delay'
 
const STATE_LAG = 'lag'
 
const STATE_UP = 'up'
 

Detailed Description

Basic DB load monitor with no external dependencies.

This uses both local server and local datacenter caches for DB 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 42 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: .8]
  • lagWarnThreshold: how many seconds of lag trigger warnings [default: 10]

Implements Wikimedia\Rdbms\ILoadMonitor.

Definition at line 82 of file LoadMonitor.php.

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

Member Function Documentation

◆ computeServerState()

Wikimedia\Rdbms\LoadMonitor::computeServerState ( int  $i,
?array  $priorState 
)
protected
Parameters
int$i
array | null$priorState
Returns
array<string,mixed>
Exceptions
DBAccessError

Definition at line 219 of file LoadMonitor.php.

◆ getCurrentTime()

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

Definition at line 420 of file LoadMonitor.php.

◆ getLagTimes()

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

Get an estimate of replication lag (in seconds) for the specified servers.

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 116 of file LoadMonitor.php.

◆ getServerStates()

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

Get a server gauge map for the specified servers.

Parameters
int[]$serverIndexes
Returns
array<int,array>

Implements Wikimedia\Rdbms\ILoadMonitor.

Reimplemented in Wikimedia\Rdbms\LoadMonitorNull.

Definition at line 127 of file LoadMonitor.php.

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

◆ getWeightScale()

Wikimedia\Rdbms\LoadMonitor::getWeightScale ( array  $state)
protected
Parameters
array$state
Returns
float

Definition at line 308 of file LoadMonitor.php.

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

◆ isStateFresh()

Wikimedia\Rdbms\LoadMonitor::isStateFresh (   $state,
  $now 
)
protected
Parameters
array | null$state
float$now
Returns
bool

Definition at line 335 of file LoadMonitor.php.

◆ isStateRefreshDue()

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

Definition at line 354 of file LoadMonitor.php.

◆ makeStateKey()

Wikimedia\Rdbms\LoadMonitor::makeStateKey ( IStoreKeyEncoder  $cache,
int  $i 
)
protected

Definition at line 202 of file LoadMonitor.php.

References IStoreKeyEncoder\makeGlobalKey().

◆ 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 377 of file LoadMonitor.php.

◆ newInitialServerState()

Wikimedia\Rdbms\LoadMonitor::newInitialServerState ( )
protected
Returns
array<string,mixed>

Definition at line 317 of file LoadMonitor.php.

◆ 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 102 of file LoadMonitor.php.

References Wikimedia\Rdbms\LoadMonitor\getServerStates(), and Wikimedia\Rdbms\LoadMonitor\getWeightScale().

◆ setLogger()

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

Definition at line 94 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 98 of file LoadMonitor.php.

Member Data Documentation

◆ $lb

ILoadBalancer Wikimedia\Rdbms\LoadMonitor::$lb
protected

Definition at line 44 of file LoadMonitor.php.

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

◆ $logger

LoggerInterface Wikimedia\Rdbms\LoadMonitor::$logger
protected

Definition at line 50 of file LoadMonitor.php.

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

◆ $srvCache

BagOStuff Wikimedia\Rdbms\LoadMonitor::$srvCache
protected

Definition at line 46 of file LoadMonitor.php.

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

◆ $statsd

StatsdDataFactoryInterface Wikimedia\Rdbms\LoadMonitor::$statsd
protected

Definition at line 52 of file LoadMonitor.php.

◆ $wanCache

WANObjectCache Wikimedia\Rdbms\LoadMonitor::$wanCache
protected

Definition at line 48 of file LoadMonitor.php.


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