28require_once __DIR__ .
'/../includes/Benchmarker.php';
38 parent::__construct();
46 $this->
error(
"CDN purge benchmark doesn't do much without CDN support on." );
50 $lengths = [ intval( $this->
getOption(
'count' ) ) ];
52 $lengths = [ 1, 10, 100 ];
54 foreach ( $lengths as $length ) {
55 $urls = $this->randomUrlList( $length );
56 $trial = $this->benchCdn( $urls );
57 $this->
output( $trial .
"\n" );
69 private function benchCdn( $urls, $trials = 1 ) {
70 $start = microtime(
true );
71 for ( $i = 0; $i < $trials; $i++ ) {
72 CdnCacheUpdate::purge( $urls );
74 $delta = microtime(
true ) - $start;
75 $pertrial = $delta / $trials;
76 $pertitle = $pertrial / count( $urls );
78 return sprintf(
"%4d titles in %6.2fms (%6.2fms each)",
79 count( $urls ), $pertrial * 1000.0, $pertitle * 1000.0 );
87 private function randomUrlList( $length ) {
89 for ( $i = 0; $i < $length; $i++ ) {
90 $list[] = $this->randomUrl();
101 private function randomUrl() {
112 private function randomTitle() {
114 $length = mt_rand( 1, 20 );
115 for ( $i = 0; $i < $length; $i++ ) {
116 $str .= chr( mt_rand( ord(
'a' ), ord(
'z' ) ) );
119 return ucfirst( $str );
125require_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.