MediaWiki  1.33.0
benchmarkPurge.php
Go to the documentation of this file.
1 <?php
24 require_once __DIR__ . '/Benchmarker.php';
25 
31 class BenchmarkPurge extends Benchmarker {
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++ ) {
66  CdnCacheUpdate::purge( $urls );
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() {
96  global $wgServer, $wgArticlePath;
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 
118 require_once RUN_MAINTENANCE_IF_MAIN;
CdnCacheUpdate\purge
static purge(array $urlArr)
Purges a list of CDN nodes defined in $wgSquidServers.
Definition: CdnCacheUpdate.php:91
Maintenance\fatalError
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Definition: Maintenance.php:485
captcha-old.count
count
Definition: captcha-old.py:249
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:329
BenchmarkPurge\__construct
__construct()
Default constructor.
Definition: benchmarkPurge.php:32
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
$wgUseSquid
$wgUseSquid
Enable/disable CDN.
Definition: DefaultSettings.php:2708
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
BenchmarkPurge\randomUrl
randomUrl()
Return a random URL of the wiki.
Definition: benchmarkPurge.php:95
BenchmarkPurge\execute
execute()
Do the actual work.
Definition: benchmarkPurge.php:37
BenchmarkPurge
Maintenance script that benchmarks Squid purge.
Definition: benchmarkPurge.php:31
$wgServer
$wgServer
URL of the server.
Definition: DefaultSettings.php:106
Benchmarker
Base class for benchmark scripts.
Definition: Benchmarker.php:40
$wgSquidServers
$wgSquidServers
List of proxy servers to purge on changes; default port is 80.
Definition: DefaultSettings.php:2798
$wgArticlePath
$wgArticlePath
Definition: img_auth.php:46
Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition: Maintenance.php:283
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:434
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
BenchmarkPurge\benchSquid
benchSquid( $urls, $trials=1)
Run a bunch of URLs through CdnCacheUpdate::purge() to benchmark Squid response times.
Definition: benchmarkPurge.php:63
Maintenance\hasOption
hasOption( $name)
Checks to see if a particular option exists.
Definition: Maintenance.php:269
BenchmarkPurge\randomTitle
randomTitle()
Create a random title string (not necessarily a Title object).
Definition: benchmarkPurge.php:106
$maintClass
$maintClass
Definition: benchmarkPurge.php:117
BenchmarkPurge\randomUrlList
randomUrlList( $length)
Get an array of randomUrl()'s.
Definition: benchmarkPurge.php:81