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 logging a warning [default: 500]

 
 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 logging a warning [default: 500]

Implements Wikimedia\Rdbms\ILoadMonitor.

Definition at line 72 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 195 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 312 of file LoadMonitor.php.

◆ getServerStates()

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

Definition at line 124 of file LoadMonitor.php.

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

◆ getStateFromWanCache()

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

Definition at line 151 of file LoadMonitor.php.

◆ makeStateKey()

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

Definition at line 178 of file LoadMonitor.php.

References IStoreKeyEncoder\makeGlobalKey().

◆ newInitialServerState()

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

Definition at line 268 of file LoadMonitor.php.

◆ scaleLoads()

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

Perform load ratio adjustment before deciding which server to use.

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

Implements Wikimedia\Rdbms\ILoadMonitor.

Reimplemented in Wikimedia\Rdbms\LoadMonitorNull.

Definition at line 90 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 82 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 320 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 86 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: