MediaWiki master
benchmarkPurge.php
Go to the documentation of this file.
1<?php
24require_once __DIR__ . '/../includes/Benchmarker.php';
25
27
34 public function __construct() {
35 parent::__construct();
36 $this->addDescription( 'Benchmark the CDN purge functions.' );
37 }
38
39 public function execute() {
41
42 if ( !$wgUseCdn ) {
43 $this->error( "CDN purge benchmark doesn't do much without CDN support on." );
44 } else {
45 $this->output( "There are " . count( $wgCdnServers ) . " defined CDN servers:\n" );
46 if ( $this->hasOption( 'count' ) ) {
47 $lengths = [ intval( $this->getOption( 'count' ) ) ];
48 } else {
49 $lengths = [ 1, 10, 100 ];
50 }
51 foreach ( $lengths as $length ) {
52 $urls = $this->randomUrlList( $length );
53 $trial = $this->benchCdn( $urls );
54 $this->output( $trial . "\n" );
55 }
56 }
57 }
58
66 private function benchCdn( $urls, $trials = 1 ) {
67 $start = microtime( true );
68 for ( $i = 0; $i < $trials; $i++ ) {
69 CdnCacheUpdate::purge( $urls );
70 }
71 $delta = microtime( true ) - $start;
72 $pertrial = $delta / $trials;
73 $pertitle = $pertrial / count( $urls );
74
75 return sprintf( "%4d titles in %6.2fms (%6.2fms each)",
76 count( $urls ), $pertrial * 1000.0, $pertitle * 1000.0 );
77 }
78
84 private function randomUrlList( $length ) {
85 $list = [];
86 for ( $i = 0; $i < $length; $i++ ) {
87 $list[] = $this->randomUrl();
88 }
89
90 return $list;
91 }
92
98 private function randomUrl() {
100
101 return $wgServer . str_replace( '$1', $this->randomTitle(), $wgArticlePath );
102 }
103
109 private function randomTitle() {
110 $str = '';
111 $length = mt_rand( 1, 20 );
112 for ( $i = 0; $i < $length; $i++ ) {
113 $str .= chr( mt_rand( ord( 'a' ), ord( 'z' ) ) );
114 }
115
116 return ucfirst( $str );
117 }
118}
119
120$maintClass = BenchmarkPurge::class;
121require_once RUN_MAINTENANCE_IF_MAIN;
$maintClass
Maintenance script that benchmarks CDN purge.
__construct()
Default constructor.
execute()
Do the actual work.
Base class for benchmark scripts.
error( $err, $die=0)
Throw an error to the user.
output( $out, $channel=null)
Throw some output to the user.
hasOption( $name)
Checks to see if a particular option was set.
addDescription( $text)
Set the description text.
getOption( $name, $default=null)
Get an option, or return the default.
Handles purging the appropriate CDN objects given a list of URLs or Title instances.
$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.