MediaWiki REL1_33
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 Squid purge functions.' );
35 }
36
37 public function execute() {
39 if ( !$wgUseSquid ) {
40 $this->fatalError( "Squid purge benchmark doesn't do much without squid support on." );
41 } else {
42 $this->output( "There are " . count( $wgSquidServers ) . " defined squid servers:\n" );
43 if ( $this->hasOption( 'count' ) ) {
44 $lengths = [ intval( $this->getOption( 'count' ) ) ];
45 } else {
46 $lengths = [ 1, 10, 100 ];
47 }
48 foreach ( $lengths as $length ) {
49 $urls = $this->randomUrlList( $length );
50 $trial = $this->benchSquid( $urls );
51 $this->output( $trial . "\n" );
52 }
53 }
54 }
55
63 private function benchSquid( $urls, $trials = 1 ) {
64 $start = microtime( true );
65 for ( $i = 0; $i < $trials; $i++ ) {
67 }
68 $delta = microtime( true ) - $start;
69 $pertrial = $delta / $trials;
70 $pertitle = $pertrial / count( $urls );
71
72 return sprintf( "%4d titles in %6.2fms (%6.2fms each)",
73 count( $urls ), $pertrial * 1000.0, $pertitle * 1000.0 );
74 }
75
81 private function randomUrlList( $length ) {
82 $list = [];
83 for ( $i = 0; $i < $length; $i++ ) {
84 $list[] = $this->randomUrl();
85 }
86
87 return $list;
88 }
89
95 private function randomUrl() {
97
98 return $wgServer . str_replace( '$1', $this->randomTitle(), $wgArticlePath );
99 }
100
106 private function randomTitle() {
107 $str = '';
108 $length = mt_rand( 1, 20 );
109 for ( $i = 0; $i < $length; $i++ ) {
110 $str .= chr( mt_rand( ord( 'a' ), ord( 'z' ) ) );
111 }
112
113 return ucfirst( $str );
114 }
115}
116
117$maintClass = BenchmarkPurge::class;
118require_once RUN_MAINTENANCE_IF_MAIN;
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
$wgUseSquid
Enable/disable CDN.
$wgSquidServers
List of proxy servers to purge on changes; default port is 80.
$wgServer
URL of the server.
$maintClass
Maintenance script that benchmarks Squid purge.
randomUrl()
Return a random URL of the wiki.
benchSquid( $urls, $trials=1)
Run a bunch of URLs through CdnCacheUpdate::purge() to benchmark Squid response times.
__construct()
Default constructor.
randomTitle()
Create a random title string (not necessarily a Title object).
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 $wgSquidServers.
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.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
$wgArticlePath
Definition img_auth.php:46
require_once RUN_MAINTENANCE_IF_MAIN