14require_once __DIR__ .
'/../includes/Benchmarker.php';
24 parent::__construct();
32 $this->
error(
"CDN purge benchmark doesn't do much without CDN support on." );
36 $lengths = [ intval( $this->
getOption(
'count' ) ) ];
38 $lengths = [ 1, 10, 100 ];
40 foreach ( $lengths as $length ) {
41 $urls = $this->randomUrlList( $length );
42 $trial = $this->benchCdn( $urls );
43 $this->
output( $trial .
"\n" );
55 private function benchCdn( $urls, $trials = 1 ) {
56 $start = microtime(
true );
57 for ( $i = 0; $i < $trials; $i++ ) {
58 CdnCacheUpdate::purge( $urls );
60 $delta = microtime(
true ) - $start;
61 $pertrial = $delta / $trials;
62 $pertitle = $pertrial / count( $urls );
64 return sprintf(
"%4d titles in %6.2fms (%6.2fms each)",
65 count( $urls ), $pertrial * 1000.0, $pertitle * 1000.0 );
73 private function randomUrlList( $length ) {
75 for ( $i = 0; $i < $length; $i++ ) {
76 $list[] = $this->randomUrl();
87 private function randomUrl() {
98 private function randomTitle() {
100 $length = mt_rand( 1, 20 );
101 for ( $i = 0; $i < $length; $i++ ) {
102 $str .= chr( mt_rand( ord(
'a' ), ord(
'z' ) ) );
105 return ucfirst( $str );
111require_once RUN_MAINTENANCE_IF_MAIN;
Maintenance script that benchmarks CDN purge.
__construct()
Default constructor.
execute()
Do the actual work.
Base class for benchmark scripts.
output( $out, $channel=null)
Throw some output to the user.
hasOption( $name)
Checks to see if a particular option was set.
getOption( $name, $default=null)
Get an option, or return the default.
error( $err, $die=0)
Throw an error to the user.
addDescription( $text)
Set the description text.
$wgUseCdn
Config variable stub for the UseCdn setting, for use by phpdoc and IDEs.
$wgArticlePath
Config variable stub for the ArticlePath setting, for use by phpdoc and IDEs.
$wgServer
Config variable stub for the Server setting, for use by phpdoc and IDEs.
$wgCdnServers
Config variable stub for the CdnServers setting, for use by phpdoc and IDEs.