MediaWiki REL1_33
Wikimedia\Rdbms\TransactionProfiler Class Reference

Helper class that detects high-contention DB queries via profiling calls. More...

Inheritance diagram for Wikimedia\Rdbms\TransactionProfiler:
Collaboration diagram for Wikimedia\Rdbms\TransactionProfiler:

Public Member Functions

 __construct ()
 
 recordConnection ( $server, $db, $isMaster)
 Mark a DB as having been connected to with a new handle.
 
 recordQueryCompletion ( $query, $sTime, $isWrite=false, $n=0)
 Register the name and time of a method for slow DB trx detection.
 
 redefineExpectations (array $expects, $fname)
 Clear all expectations and hit counters and set new performance expectations.
 
 resetExpectations ()
 Reset all performance expectations and hit counters.
 
 setExpectation ( $event, $value, $fname)
 Set performance expectations.
 
 setExpectations (array $expects, $fname)
 Set one or multiple performance expectations.
 
 setLogger (LoggerInterface $logger)
 
 setSilenced ( $value)
 
 transactionWritingIn ( $server, $db, $id)
 Mark a DB as in a transaction with one or more writes pending.
 
 transactionWritingOut ( $server, $db, $id, $writeTime=0.0, $affected=0)
 Mark a DB as no longer in a transaction.
 

Protected Member Functions

 reportExpectationViolated ( $expect, $query, $actual)
 

Protected Attributes

float $dbLockThreshold = 3.0
 Seconds.
 
array $dbTrxHoldingLocks = []
 transaction ID => (write start time, list of DBs involved)
 
array $dbTrxMethodTimes = []
 transaction ID => list of (query name, start time, end time)
 
float $eventThreshold = 0.25
 Seconds.
 
array $expect
 
array $expectBy = []
 
array $hits
 
bool $silenced = false
 

Private Attributes

LoggerInterface $logger
 

Detailed Description

Helper class that detects high-contention DB queries via profiling calls.

This class is meant to work with an IDatabase object, which manages queries

Since
1.24

Definition at line 38 of file TransactionProfiler.php.

Constructor & Destructor Documentation

◆ __construct()

Wikimedia\Rdbms\TransactionProfiler::__construct ( )

Member Function Documentation

◆ recordConnection()

Wikimedia\Rdbms\TransactionProfiler::recordConnection (   $server,
  $db,
  $isMaster 
)

Mark a DB as having been connected to with a new handle.

Note that there can be multiple connections to a single DB.

Parameters
string$serverDB server
string$dbDB name
bool$isMaster

Definition at line 178 of file TransactionProfiler.php.

References Wikimedia\Rdbms\TransactionProfiler\reportExpectationViolated().

◆ recordQueryCompletion()

Wikimedia\Rdbms\TransactionProfiler::recordQueryCompletion (   $query,
  $sTime,
  $isWrite = false,
  $n = 0 
)

Register the name and time of a method for slow DB trx detection.

This assumes that all queries are synchronous (non-overlapping)

Parameters
string$queryFunction name or generalized SQL
float$sTimeStarting UNIX wall time
bool$isWriteWhether this is a write query
int$nNumber of affected/read rows

Definition at line 226 of file TransactionProfiler.php.

References $name, $query, as, and Wikimedia\Rdbms\TransactionProfiler\reportExpectationViolated().

◆ redefineExpectations()

Wikimedia\Rdbms\TransactionProfiler::redefineExpectations ( array  $expects,
  $fname 
)

Clear all expectations and hit counters and set new performance expectations.

Use this to apply a totally different set of expectations for a different part of the request, such as during "post-send" (execution after HTTP response completion)

Parameters
array$expectsMap of (event => limit)
string$fname
Since
1.33

Definition at line 164 of file TransactionProfiler.php.

References $fname, Wikimedia\Rdbms\TransactionProfiler\resetExpectations(), and Wikimedia\Rdbms\TransactionProfiler\setExpectations().

◆ reportExpectationViolated()

Wikimedia\Rdbms\TransactionProfiler::reportExpectationViolated (   $expect,
  $query,
  $actual 
)
protected

◆ resetExpectations()

Wikimedia\Rdbms\TransactionProfiler::resetExpectations ( )

Reset all performance expectations and hit counters.

Use this for unit testing or before applying a totally different set of expectations for a different part of the request, such as during "post-send" (execution after HTTP response completion)

Since
1.25

Definition at line 142 of file TransactionProfiler.php.

References as.

Referenced by Wikimedia\Rdbms\TransactionProfiler\redefineExpectations().

◆ setExpectation()

Wikimedia\Rdbms\TransactionProfiler::setExpectation (   $event,
  $value,
  $fname 
)

Set performance expectations.

With conflicting expectations, the most narrow ones will be used

Parameters
string$event(writes,queries,conns,mConns)
int$valueMaximum count of the event
string$fnameCaller
Since
1.25

Definition at line 107 of file TransactionProfiler.php.

References $fname, and $value.

Referenced by Wikimedia\Rdbms\TransactionProfiler\setExpectations().

◆ setExpectations()

Wikimedia\Rdbms\TransactionProfiler::setExpectations ( array  $expects,
  $fname 
)

Set one or multiple performance expectations.

With conflicting expectations, the most narrow ones will be used

Use this to initialize expectations or make them stricter mid-request

Parameters
array$expectsMap of (event => limit)
string$fname
Since
1.26

Definition at line 127 of file TransactionProfiler.php.

References $fname, $value, as, and Wikimedia\Rdbms\TransactionProfiler\setExpectation().

Referenced by Wikimedia\Rdbms\TransactionProfiler\redefineExpectations().

◆ setLogger()

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

◆ setSilenced()

Wikimedia\Rdbms\TransactionProfiler::setSilenced (   $value)
Parameters
bool$value
Returns
bool Old value
Since
1.28

Definition at line 90 of file TransactionProfiler.php.

References Wikimedia\Rdbms\TransactionProfiler\$silenced, and $value.

◆ transactionWritingIn()

Wikimedia\Rdbms\TransactionProfiler::transactionWritingIn (   $server,
  $db,
  $id 
)

Mark a DB as in a transaction with one or more writes pending.

Note that there can be multiple connections to a single DB.

Parameters
string$serverDB server
string$dbDB name
string$idID string of transaction

Definition at line 199 of file TransactionProfiler.php.

References $name, and as.

◆ transactionWritingOut()

Wikimedia\Rdbms\TransactionProfiler::transactionWritingOut (   $server,
  $db,
  $id,
  $writeTime = 0.0,
  $affected = 0 
)

Mark a DB as no longer in a transaction.

This will check if locks are possibly held for longer than needed and log any affected transactions to a special DB log. Note that there can be multiple connections to a single DB.

Parameters
string$serverDB server
string$dbDB name
string$idID string of transaction
float$writeTimeTime spent in write queries
int$affectedNumber of rows affected by writes

Definition at line 297 of file TransactionProfiler.php.

References $name, $query, as, list, and Wikimedia\Rdbms\TransactionProfiler\reportExpectationViolated().

Member Data Documentation

◆ $dbLockThreshold

float Wikimedia\Rdbms\TransactionProfiler::$dbLockThreshold = 3.0
protected

Seconds.

Definition at line 40 of file TransactionProfiler.php.

◆ $dbTrxHoldingLocks

array Wikimedia\Rdbms\TransactionProfiler::$dbTrxHoldingLocks = []
protected

transaction ID => (write start time, list of DBs involved)

Definition at line 47 of file TransactionProfiler.php.

◆ $dbTrxMethodTimes

array Wikimedia\Rdbms\TransactionProfiler::$dbTrxMethodTimes = []
protected

transaction ID => list of (query name, start time, end time)

Definition at line 49 of file TransactionProfiler.php.

◆ $eventThreshold

float Wikimedia\Rdbms\TransactionProfiler::$eventThreshold = 0.25
protected

Seconds.

Definition at line 42 of file TransactionProfiler.php.

◆ $expect

array Wikimedia\Rdbms\TransactionProfiler::$expect
protected
Initial value:
= [
'writes' => INF,
'queries' => INF,
'conns' => INF,
'masterConns' => INF,
'maxAffected' => INF,
'readQueryRows' => INF,
'readQueryTime' => INF,
'writeQueryTime' => INF
]

Definition at line 59 of file TransactionProfiler.php.

Referenced by Wikimedia\Rdbms\TransactionProfiler\reportExpectationViolated().

◆ $expectBy

array Wikimedia\Rdbms\TransactionProfiler::$expectBy = []
protected

Definition at line 70 of file TransactionProfiler.php.

◆ $hits

array Wikimedia\Rdbms\TransactionProfiler::$hits
protected
Initial value:
= [
'writes' => 0,
'queries' => 0,
'conns' => 0,
'masterConns' => 0
]

Definition at line 52 of file TransactionProfiler.php.

◆ $logger

LoggerInterface Wikimedia\Rdbms\TransactionProfiler::$logger
private

◆ $silenced

bool Wikimedia\Rdbms\TransactionProfiler::$silenced = false
protected

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