63 'readQueryTime' => INF,
64 'writeQueryTime' => INF
105 $this->expect[$event] = isset( $this->expect[$event] )
106 ? min( $this->expect[$event],
$value )
108 if ( $this->expect[$event] ==
$value ) {
109 $this->expectBy[$event] =
$fname;
123 foreach ( $expects
as $event =>
$value ) {
134 foreach ( $this->hits
as &$val ) {
138 foreach ( $this->expect
as &$val ) {
142 $this->expectBy = [];
156 if ( $this->hits[
'conns']++ == $this->expect[
'conns'] ) {
159 if ( $isMaster && $this->hits[
'masterConns']++ == $this->expect[
'masterConns'] ) {
174 $name =
"{$server} ({$db}) (TRX#$id)";
175 if ( isset( $this->dbTrxHoldingLocks[
$name] ) ) {
176 $this->logger->info(
"Nested transaction for '$name' - out of sync." );
178 $this->dbTrxHoldingLocks[
$name] = [
179 'start' => microtime(
true ),
182 $this->dbTrxMethodTimes[
$name] = [];
184 foreach ( $this->dbTrxHoldingLocks
as $name => &$info ) {
186 $info[
'conns'][
$name] = 1;
201 $eTime = microtime(
true );
202 $elapsed = ( $eTime - $sTime );
204 if ( $isWrite && $n > $this->expect[
'maxAffected'] ) {
206 "Query affected $n row(s):\n" .
$query .
"\n" .
211 if ( $this->hits[
'queries']++ == $this->expect[
'queries'] ) {
214 if ( $isWrite && $this->hits[
'writes']++ == $this->expect[
'writes'] ) {
218 if ( !$isWrite && $elapsed > $this->expect[
'readQueryTime'] ) {
221 if ( $isWrite && $elapsed > $this->expect[
'writeQueryTime'] ) {
225 if ( !$this->dbTrxHoldingLocks ) {
228 } elseif ( !$isWrite && $elapsed < $this->eventThreshold ) {
233 foreach ( $this->dbTrxHoldingLocks
as $name => $info ) {
234 $lastQuery = end( $this->dbTrxMethodTimes[
$name] );
237 $lastEnd = $lastQuery[2];
238 if ( $sTime >= $lastEnd ) {
239 if ( ( $sTime - $lastEnd ) > $this->eventThreshold ) {
241 $this->dbTrxMethodTimes[
$name][] = [
'...delay...', $lastEnd, $sTime ];
243 $this->dbTrxMethodTimes[
$name][] = [
$query, $sTime, $eTime ];
247 if ( $sTime >= $info[
'start'] ) {
248 $this->dbTrxMethodTimes[
$name][] = [
$query, $sTime, $eTime ];
267 $name =
"{$server} ({$db}) (TRX#$id)";
268 if ( !isset( $this->dbTrxMethodTimes[
$name] ) ) {
269 $this->logger->info(
"Detected no transaction for '$name' - out of sync." );
276 if ( $writeTime > $this->expect[
'writeQueryTime'] ) {
279 "[transaction $id writes to {$server} ({$db})]",
285 $lastQuery = end( $this->dbTrxMethodTimes[$name] );
287 $now = microtime(
true );
288 $lastEnd = $lastQuery[2];
289 if ( ( $now - $lastEnd ) > $this->eventThreshold ) {
290 $this->dbTrxMethodTimes[
$name][] = [
'...delay...', $lastEnd, $now ];
294 foreach ( $this->dbTrxMethodTimes[$name]
as $info ) {
295 $elapsed = ( $info[2] - $info[1] );
296 if ( $elapsed >= $this->dbLockThreshold ) {
303 foreach ( $this->dbTrxMethodTimes[$name]
as $i => $info ) {
305 $trace .= sprintf(
"%d\t%.6f\t%s\n", $i, ( $end - $sTime ),
$query );
307 $this->logger->info(
"Sub-optimal transaction on DB(s) [{dbs}]: \n{trace}", [
308 'dbs' => implode(
', ', array_keys( $this->dbTrxHoldingLocks[$name][
'conns'] ) ),
312 unset( $this->dbTrxHoldingLocks[$name] );
313 unset( $this->dbTrxMethodTimes[$name] );
322 if ( $this->silenced ) {
327 $by = $this->expectBy[
$expect];
328 $actual = ( $actual !== null ) ?
" (actual: $actual)" :
"";
331 "Expectation ($expect <= $n) by $by not met$actual:\n$query\n" .
array $dbTrxMethodTimes
transaction ID => list of (query name, start time, end time)
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
the array() calling protocol came about after MediaWiki 1.4rc1.
null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
float $dbLockThreshold
Seconds.
reportExpectationViolated($expect, $query, $actual=null)
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
array $dbTrxHoldingLocks
transaction ID => (write start time, list of DBs involved)
float $eventThreshold
Seconds.
array array array $expectBy
setExpectations(array $expects, $fname)
Set multiple performance expectations.
Helper class that detects high-contention DB queries via profiling calls.
resetExpectations()
Reset performance expectations and hit counters.
setExpectation($event, $value, $fname)
Set performance expectations.
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
setLogger(LoggerInterface $logger)
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
if(!defined( 'MEDIAWIKI')) $fname
This file is not a valid entry point, perform no further processing unless MEDIAWIKI is defined...
transactionWritingOut($server, $db, $id, $writeTime=0.0)
Mark a DB as no longer in a transaction.
recordConnection($server, $db, $isMaster)
Mark a DB as having been connected to with a new handle.
transactionWritingIn($server, $db, $id)
Mark a DB as in a transaction with one or more writes pending.
recordQueryCompletion($query, $sTime, $isWrite=false, $n=0)
Register the name and time of a method for slow DB trx detection.
Allows to change the fields on the form that will be generated $name