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, $options)
 Construct a new LoadMonitor with a given LoadBalancer parent.
Parameters
ILoadBalancer$lbLoadBalancer this instance serves
BagOStuff$sCacheLocal server memory cache
WANObjectCache$wCacheLocal cluster memory cache
array$optionsAdditional parameters include:
  • maxConnCount: maximum number of connections before circuit breaking to kick in [default: infinity]

 
 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 $previousState)
 
 getCurrentTime ()
 
 getServerStates (array $serverIndexes)
 
 getStateFromWanCache ( $i, ?array $srvPrevState)
 
 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_CONN_COUNT = 'conn_count'
 
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.

Definition at line 41 of file LoadMonitor.php.

Constructor & Destructor Documentation

◆ __construct()

Wikimedia\Rdbms\LoadMonitor::__construct ( ILoadBalancer $lb,
BagOStuff $srvCache,
WANObjectCache $wCache,
$options )

Construct a new LoadMonitor with a given LoadBalancer parent.

Parameters
ILoadBalancer$lbLoadBalancer this instance serves
BagOStuff$sCacheLocal server memory cache
WANObjectCache$wCacheLocal cluster memory cache
array$optionsAdditional parameters include:
  • maxConnCount: maximum number of connections before circuit breaking to kick in [default: infinity]

Implements Wikimedia\Rdbms\ILoadMonitor.

Definition at line 73 of file LoadMonitor.php.

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

Member Function Documentation

◆ computeServerState()

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

Definition at line 221 of file LoadMonitor.php.

References Wikimedia\Rdbms\ILoadBalancer\CONN_SILENCE_ERRORS, Wikimedia\Rdbms\ILoadBalancer\CONN_UNTRACKED_GAUGE, and Wikimedia\Rdbms\ILoadBalancer\DOMAIN_ANY.

◆ getCurrentTime()

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

Definition at line 338 of file LoadMonitor.php.

◆ getServerStates()

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

Definition at line 150 of file LoadMonitor.php.

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

◆ getStateFromWanCache()

Wikimedia\Rdbms\LoadMonitor::getStateFromWanCache ( $i,
?array $srvPrevState )
protected

Definition at line 177 of file LoadMonitor.php.

◆ makeStateKey()

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

◆ newInitialServerState()

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

Definition at line 294 of file LoadMonitor.php.

◆ scaleLoads()

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

Perform load ratio adjustment before deciding which server to use.

Parameters
array<int,int|float>&$weightByServer Map of (server index => weight)

Implements Wikimedia\Rdbms\ILoadMonitor.

Reimplemented in Wikimedia\Rdbms\LoadMonitorNull.

Definition at line 96 of file LoadMonitor.php.

References Wikimedia\Rdbms\LoadMonitor\getServerStates(), and Wikimedia\Rdbms\ILoadMonitor\STATE_CONN_COUNT.

◆ setLogger()

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

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

◆ setStatsdDataFactory()

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

Sets a StatsdDataFactory instance on the object.

Parameters
StatsdDataFactoryInterface$statsFactory
Returns
null

Implements Wikimedia\Stats\StatsdAwareInterface.

Definition at line 92 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: