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, LoggerInterface $logger, StatsFactory $statsFactory, $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
LoggerInterface$loggerPSR-3 logger instance
StatsFactory$statsFactoryStatsFactory instance
array$optionsAdditional parameters include:
  • maxConnCount: maximum number of connections before circuit breaking applies [default: infinity]

 scaleLoads (array &$weightByServer)
 Perform load ratio adjustment before deciding which server to use.
 setLogger (LoggerInterface $logger)
 setMockTime (&$time)

Protected Member Functions

 computeServerState (int $i, ?array $previousState)
 getCurrentTime ()
 getServerStates (array $serverIndexes)
 getStateFromWanCache (int $i, ?array $srvPrevState)
 makeStateKey (IStoreKeyEncoder $cache, int $i)
 newInitialServerState ()

Protected Attributes

ILoadBalancer $lb
LoggerInterface $logger
BagOStuff $srvCache
StatsFactory $statsFactory
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 25 of file LoadMonitor.php.

Constructor & Destructor Documentation

◆ __construct()

Wikimedia\Rdbms\LoadMonitor::__construct ( ILoadBalancer $lb,
BagOStuff $srvCache,
WANObjectCache $wCache,
LoggerInterface $logger,
StatsFactory $statsFactory,
$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
LoggerInterface$loggerPSR-3 logger instance
StatsFactory$statsFactoryStatsFactory instance
array$optionsAdditional parameters include:
  • maxConnCount: maximum number of connections before circuit breaking applies [default: infinity]

Implements Wikimedia\Rdbms\ILoadMonitor.

Definition at line 57 of file LoadMonitor.php.

References $lb, $logger, $srvCache, and $statsFactory.

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

References Wikimedia\Rdbms\ILoadBalancer\CONN_SILENCE_ERRORS, Wikimedia\Rdbms\ILoadBalancer\CONN_UNTRACKED_GAUGE, Wikimedia\Rdbms\ILoadBalancer\DOMAIN_ANY, getCurrentTime(), and newInitialServerState().

Referenced by getStateFromWanCache().

◆ getCurrentTime()

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

Definition at line 326 of file LoadMonitor.php.

Referenced by computeServerState().

◆ getServerStates()

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

Definition at line 137 of file LoadMonitor.php.

References makeStateKey().

Referenced by scaleLoads().

◆ getStateFromWanCache()

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

Definition at line 164 of file LoadMonitor.php.

References computeServerState(), and makeStateKey().

◆ makeStateKey()

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

Definition at line 191 of file LoadMonitor.php.

References return.

Referenced by getServerStates(), and getStateFromWanCache().

◆ newInitialServerState()

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

Definition at line 284 of file LoadMonitor.php.

Referenced by computeServerState().

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

References getServerStates().

◆ setLogger()

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

Definition at line 79 of file LoadMonitor.php.

References $logger.

◆ setMockTime()

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

Definition at line 334 of file LoadMonitor.php.

Member Data Documentation

◆ $lb

ILoadBalancer Wikimedia\Rdbms\LoadMonitor::$lb
protected

Definition at line 27 of file LoadMonitor.php.

Referenced by __construct().

◆ $logger

LoggerInterface Wikimedia\Rdbms\LoadMonitor::$logger
protected

Definition at line 33 of file LoadMonitor.php.

Referenced by __construct(), and setLogger().

◆ $srvCache

BagOStuff Wikimedia\Rdbms\LoadMonitor::$srvCache
protected

Definition at line 29 of file LoadMonitor.php.

Referenced by __construct().

◆ $statsFactory

StatsFactory Wikimedia\Rdbms\LoadMonitor::$statsFactory
protected

Definition at line 35 of file LoadMonitor.php.

Referenced by __construct().

◆ $wanCache

WANObjectCache Wikimedia\Rdbms\LoadMonitor::$wanCache
protected

Definition at line 31 of file LoadMonitor.php.


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