MediaWiki REL1_39
LoadMonitorMySQL.php
Go to the documentation of this file.
1<?php
21namespace Wikimedia\Rdbms;
22
23use BagOStuff;
25
34 private $warmCacheRatio;
35
36 public function __construct(
37 ILoadBalancer $lb, BagOStuff $srvCache, WANObjectCache $wCache, array $options = []
38 ) {
39 parent::__construct( $lb, $srvCache, $wCache, $options );
40
41 $this->warmCacheRatio = $options['warmCacheRatio'] ?? 0.0;
42 }
43
44 protected function getWeightScale( $index, IDatabase $conn = null ) {
45 if ( $conn === null ) {
46 return parent::getWeightScale( $index, $conn );
47 }
48
49 $weight = 1.0;
50 if ( $this->warmCacheRatio > 0 ) {
51 $res = $conn->query( 'SHOW STATUS', __METHOD__ );
52 $s = $res ? $res->fetchObject() : false;
53 if ( $s === false ) {
54 $host = $this->lb->getServerName( $index );
55 $this->replLogger->error( __METHOD__ . ": could not get status for $host" );
56 } else {
57 // https://dev.mysql.com/doc/refman/5.7/en/server-status-variables.html
58 if ( $s->Innodb_buffer_pool_pages_total > 0 ) {
59 $ratio = $s->Innodb_buffer_pool_pages_data / $s->Innodb_buffer_pool_pages_total;
60 } else {
61 $ratio = 1.0;
62 }
63 // Stop caring once $ratio >= $this->warmCacheRatio
64 $weight *= min( $ratio / $this->warmCacheRatio, 1.0 );
65 }
66 }
67
68 return $weight;
69 }
70}
Class representing a cache/ephemeral data store.
Definition BagOStuff.php:85
Multi-datacenter aware caching interface.
Basic MySQL load monitor with no external dependencies Uses memcached to cache the replication lag fo...
__construct(ILoadBalancer $lb, BagOStuff $srvCache, WANObjectCache $wCache, array $options=[])
getWeightScale( $index, IDatabase $conn=null)
Basic DB load monitor with no external dependencies.
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:39
Create and track the database connections and transactions for a given database cluster.
foreach( $mmfl['setupFiles'] as $fileName) if($queue) if(empty( $mmfl['quiet'])) $s