MediaWiki
master
Toggle main menu visibility
benchmarkPurge.php
Go to the documentation of this file.
1
<?php
9
10
use
MediaWiki\Deferred\CdnCacheUpdate
;
11
use
MediaWiki\Maintenance\Benchmarker
;
12
use Wikimedia\Timestamp\ConvertibleTimestamp;
13
14
// @codeCoverageIgnoreStart
15
require_once __DIR__ .
'/../includes/Benchmarker.php'
;
16
// @codeCoverageIgnoreEnd
17
23
class
BenchmarkPurge
extends
Benchmarker
{
24
public
function
__construct
() {
25
parent::__construct();
26
$this->
addDescription
(
'Benchmark the CDN purge functions.'
);
27
}
28
29
public
function
execute
() {
30
global
$wgUseCdn
,
$wgCdnServers
;
31
32
if
( !
$wgUseCdn
) {
33
$this->
error
(
"CDN purge benchmark doesn't do much without CDN support on."
);
34
}
else
{
35
$this->
output
(
"There are "
. count(
$wgCdnServers
) .
" defined CDN servers:\n"
);
36
if
( $this->
hasOption
(
'count'
) ) {
37
$lengths = [ intval( $this->
getOption
(
'count'
) ) ];
38
}
else
{
39
$lengths = [ 1, 10, 100 ];
40
}
41
foreach
( $lengths as $length ) {
42
$urls = $this->randomUrlList( $length );
43
$trial = $this->benchCdn( $urls );
44
$this->
output
( $trial .
"\n"
);
45
}
46
}
47
}
48
56
private
function
benchCdn( $urls, $trials = 1 ) {
57
$start = ConvertibleTimestamp::hrtime();
58
for
( $i = 0; $i < $trials; $i++ ) {
59
CdnCacheUpdate::purge
( $urls );
60
}
61
$delta = ( ConvertibleTimestamp::hrtime() - $start ) / 1e9;
62
$pertrial = $delta / $trials;
63
$pertitle = $pertrial / count( $urls );
64
65
return
sprintf(
"%4d titles in %6.2fms (%6.2fms each)"
,
66
count( $urls ), $pertrial * 1000.0, $pertitle * 1000.0 );
67
}
68
74
private
function
randomUrlList( $length ) {
75
$list = [];
76
for
( $i = 0; $i < $length; $i++ ) {
77
$list[] = $this->randomUrl();
78
}
79
80
return
$list;
81
}
82
88
private
function
randomUrl() {
89
global
$wgServer
,
$wgArticlePath
;
90
91
return
$wgServer
. str_replace(
'$1'
, $this->randomTitle(),
$wgArticlePath
);
92
}
93
99
private
function
randomTitle() {
100
$str =
''
;
101
$length = mt_rand( 1, 20 );
102
for
( $i = 0; $i < $length; $i++ ) {
103
$str .= chr( mt_rand( ord(
'a'
), ord(
'z'
) ) );
104
}
105
106
return
ucfirst( $str );
107
}
108
}
109
110
// @codeCoverageIgnoreStart
111
$maintClass
= BenchmarkPurge::class;
112
require_once RUN_MAINTENANCE_IF_MAIN;
113
// @codeCoverageIgnoreEnd
$maintClass
$maintClass
Definition
addChangeTag.php:56
BenchmarkPurge
Maintenance script that benchmarks CDN purge.
Definition
benchmarkPurge.php:23
BenchmarkPurge\__construct
__construct()
Default constructor.
Definition
benchmarkPurge.php:24
BenchmarkPurge\execute
execute()
Do the actual work.
Definition
benchmarkPurge.php:29
MediaWiki\Deferred\CdnCacheUpdate
Handles purging the appropriate CDN objects given a list of URLs or Title instances.
Definition
CdnCacheUpdate.php:23
MediaWiki\Deferred\CdnCacheUpdate\purge
static purge(array $urls)
Purges a list of CDN nodes defined in $wgCdnServers.
Definition
CdnCacheUpdate.php:95
MediaWiki\Maintenance\Benchmarker
Base class for benchmark scripts.
Definition
Benchmarker.php:29
MediaWiki\Maintenance\Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition
Maintenance.php:485
MediaWiki\Maintenance\Maintenance\error
error( $err)
Throw an error to the user.
Definition
Maintenance.php:511
MediaWiki\Maintenance\Maintenance\hasOption
hasOption( $name)
Checks to see if a particular option was set.
Definition
Maintenance.php:284
MediaWiki\Maintenance\Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition
Maintenance.php:299
MediaWiki\Maintenance\Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition
Maintenance.php:335
$wgUseCdn
$wgUseCdn
Config variable stub for the UseCdn setting, for use by phpdoc and IDEs.
Definition
config-vars.php:1719
$wgArticlePath
$wgArticlePath
Config variable stub for the ArticlePath setting, for use by phpdoc and IDEs.
Definition
config-vars.php:121
$wgServer
$wgServer
Config variable stub for the Server setting, for use by phpdoc and IDEs.
Definition
config-vars.php:25
$wgCdnServers
$wgCdnServers
Config variable stub for the CdnServers setting, for use by phpdoc and IDEs.
Definition
config-vars.php:1767
maintenance
benchmarks
benchmarkPurge.php
Generated on
for MediaWiki by
1.18.0