MediaWiki REL1_34
benchmarkPurge.php
Go to the documentation of this file.
1<?php
24require_once __DIR__ . '/Benchmarker.php';
25
32 public function __construct() {
33 parent::__construct();
34 $this->addDescription( 'Benchmark the CDN purge functions.' );
35 }
36
37 public function execute() {
39
40 if ( !$wgUseCdn ) {
41 $this->error( "CDN purge benchmark doesn't do much without CDN support on." );
42 } else {
43 $this->output( "There are " . count( $wgCdnServers ) . " defined CDN servers:\n" );
44 if ( $this->hasOption( 'count' ) ) {
45 $lengths = [ intval( $this->getOption( 'count' ) ) ];
46 } else {
47 $lengths = [ 1, 10, 100 ];
48 }
49 foreach ( $lengths as $length ) {
50 $urls = $this->randomUrlList( $length );
51 $trial = $this->benchCdn( $urls );
52 $this->output( $trial . "\n" );
53 }
54 }
55 }
56
64 private function benchCdn( $urls, $trials = 1 ) {
65 $start = microtime( true );
66 for ( $i = 0; $i < $trials; $i++ ) {
68 }
69 $delta = microtime( true ) - $start;
70 $pertrial = $delta / $trials;
71 $pertitle = $pertrial / count( $urls );
72
73 return sprintf( "%4d titles in %6.2fms (%6.2fms each)",
74 count( $urls ), $pertrial * 1000.0, $pertitle * 1000.0 );
75 }
76
82 private function randomUrlList( $length ) {
83 $list = [];
84 for ( $i = 0; $i < $length; $i++ ) {
85 $list[] = $this->randomUrl();
86 }
87
88 return $list;
89 }
90
96 private function randomUrl() {
98
99 return $wgServer . str_replace( '$1', $this->randomTitle(), $wgArticlePath );
100 }
101
107 private function randomTitle() {
108 $str = '';
109 $length = mt_rand( 1, 20 );
110 for ( $i = 0; $i < $length; $i++ ) {
111 $str .= chr( mt_rand( ord( 'a' ), ord( 'z' ) ) );
112 }
113
114 return ucfirst( $str );
115 }
116}
117
118$maintClass = BenchmarkPurge::class;
119require_once RUN_MAINTENANCE_IF_MAIN;
$wgUseCdn
Enable/disable CDN.
$wgServer
URL of the server.
$wgCdnServers
List of proxy servers to purge on changes; default port is 80.
const RUN_MAINTENANCE_IF_MAIN
$maintClass
Maintenance script that benchmarks CDN purge.
randomUrl()
Return a random URL of the wiki.
__construct()
Default constructor.
randomTitle()
Create a random title string (not necessarily a Title object).
benchCdn( $urls, $trials=1)
Run a bunch of URLs through CdnCacheUpdate::purge() to benchmark CDN response times.
randomUrlList( $length)
Get an array of randomUrl()'s.
execute()
Do the actual work.
Base class for benchmark scripts.
static purge(array $urlArr)
Purges a list of CDN nodes defined in $wgCdnServers.
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 exists.
addDescription( $text)
Set the description text.
getOption( $name, $default=null)
Get an option, or return the default.
$wgArticlePath
Definition img_auth.php:47