MediaWiki REL1_31
LoadMonitorMySQL.php
Go to the documentation of this file.
1<?php
22namespace Wikimedia\Rdbms;
23
24use BagOStuff;
26
36
37 public function __construct(
39 ) {
40 parent::__construct( $lb, $srvCache, $wCache, $options );
41
42 $this->warmCacheRatio = isset( $options['warmCacheRatio'] )
43 ? $options['warmCacheRatio']
44 : 0.0;
45 }
46
47 protected function getWeightScale( $index, IDatabase $conn = null ) {
48 if ( !$conn ) {
49 return parent::getWeightScale( $index, $conn );
50 }
51
52 $weight = 1.0;
53 if ( $this->warmCacheRatio > 0 ) {
54 $res = $conn->query( 'SHOW STATUS', __METHOD__ );
55 $s = $res ? $conn->fetchObject( $res ) : false;
56 if ( $s === false ) {
57 $host = $this->parent->getServerName( $index );
58 $this->replLogger->error( __METHOD__ . ": could not get status for $host" );
59 } else {
60 // https://dev.mysql.com/doc/refman/5.7/en/server-status-variables.html
61 if ( $s->Innodb_buffer_pool_pages_total > 0 ) {
62 $ratio = $s->Innodb_buffer_pool_pages_data / $s->Innodb_buffer_pool_pages_total;
63 } else {
64 $ratio = 1.0;
65 }
66 // Stop caring once $ratio >= $this->warmCacheRatio
67 $weight *= min( $ratio / $this->warmCacheRatio, 1.0 );
68 }
69 }
70
71 return $weight;
72 }
73}
interface is intended to be more or less compatible with the PHP memcached client.
Definition BagOStuff.php:47
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=[])
float $warmCacheRatio
What buffer pool use ratio counts as "warm" (e.g.
getWeightScale( $index, IDatabase $conn=null)
Basic DB load monitor with no external dependencies Uses memcached to cache the replication lag for a...
$res
Definition database.txt:21
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
Definition hooks.txt:2001
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:38
Database cluster connection, tracking, load balancing, and transaction manager interface.