43 public function scaleLoads( &$loads, $group =
false, $wiki =
false ) {
47 if ( count( $serverIndexes ) == 1 && reset( $serverIndexes ) == 0 ) {
48 # Single server only, just return zero without caching
53 # Randomize TTLs to reduce stampedes (4.0 - 5.0 sec)
54 $ttl = mt_rand( 4e6, 5e6 ) / 1e6;
55 # Keep keys around longer as fallbacks
58 # (a) Check the local APC cache
59 $value = $this->srvCache->get( $key );
60 if (
$value &&
$value[
'timestamp'] > ( microtime(
true ) - $ttl ) ) {
61 wfDebugLog(
'replication', __METHOD__ .
": got lag times ($key) from local cache" );
64 $staleValue =
$value ?:
false;
66 # (b) Check the shared cache and backfill APC
67 $value = $this->mainCache->get( $key );
68 if (
$value &&
$value[
'timestamp'] > ( microtime(
true ) - $ttl ) ) {
69 $this->srvCache->set( $key,
$value, $staleTTL );
70 wfDebugLog(
'replication', __METHOD__ .
": got lag times ($key) from main cache" );
74 $staleValue =
$value ?: $staleValue;
76 # (c) Cache key missing or expired; regenerate and backfill
77 if ( $this->mainCache->lock( $key, 0, 10 ) ) {
78 # Let this process alone update the cache value
84 } elseif ( $staleValue ) {
85 # Could not acquire lock but an old cache exists, so use it
86 return $staleValue[
'lagTimes'];
90 foreach ( $serverIndexes
as $i ) {
91 if ( $i == $this->parent->getWriterIndex() ) {
96 $conn = $this->parent->getAnyOpenConnection( $i );
100 $conn = $this->parent->openConnection( $i, $wiki );
105 $lagTimes[$i] =
false;
106 $host = $this->parent->getServerName( $i );
107 wfDebugLog(
'replication', __METHOD__ .
": host $host (#$i) is unreachable" );
111 $lagTimes[$i] = $conn->getLag();
112 if ( $lagTimes[$i] ===
false ) {
113 $host = $this->parent->getServerName( $i );
114 wfDebugLog(
'replication', __METHOD__ .
": host $host (#$i) is not replicating?" );
118 # Close the connection to avoid sleeper connections piling up.
119 # Note that the caller will pick one of these DBs and reconnect,
120 # which is slightly inefficient, but this only matters for the lag
121 # time cache miss cache, which is far less common that cache hits.
122 $this->parent->closeConnection( $conn );
126 # Add a timestamp key so we know when it was cached
127 $value = [
'lagTimes' => $lagTimes,
'timestamp' => microtime(
true ) ];
128 $this->mainCache->set( $key,
$value, $staleTTL );
129 $this->srvCache->set( $key,
$value, $staleTTL );
130 wfDebugLog(
'replication', __METHOD__ .
": re-calculated lag times ($key)" );
132 return $value[
'lagTimes'];
137 $this->srvCache->delete( $key );
138 $this->mainCache->delete( $key );
142 $writerIndex = $this->parent->getWriterIndex();
144 return $this->srvCache->makeGlobalKey(
145 'lag-times', $this->parent->getServerName( $writerIndex )
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
static getLocalClusterInstance()
Get the main cluster-local cache object.
getLagTimes($serverIndexes, $wiki)
Get an estimate of replication lag (in seconds) for each server.
Class for asserting that a callback happens when an dummy object leaves scope.
wfDebugLog($logGroup, $text, $dest= 'all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not...
An interface for database load monitoring.
Basic MySQL load monitor with no external dependencies Uses memcached to cache the replication lag fo...
clearCaches()
Clear any process and persistent cache of lag times.
scaleLoads(&$loads, $group=false, $wiki=false)
Perform pre-connection load ratio adjustment.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
static getLocalServerInstance($fallback=CACHE_NONE)
Factory function for CACHE_ACCEL (referenced from DefaultSettings.php)
__construct($parent)
Construct a new LoadMonitor with a given LoadBalancer parent.