MediaWiki  1.27.2
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->error( "Squid purge benchmark doesn't do much without squid support on.", true );
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";
118 require_once RUN_MAINTENANCE_IF_MAIN;
Maintenance script that benchmarks Squid purge.
$wgSquidServers
List of proxy servers to purge on changes; default port is 80.
static purge(array $urlArr)
Purges a list of CDN nodes defined in $wgSquidServers.
hasOption($name)
Checks to see if a particular param exists.
benchSquid($urls, $trials=1)
Run a bunch of URLs through SquidUpdate::purge() to benchmark Squid response times.
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
when a variable name is used in a it is silently declared as a new local masking the global
Definition: design.txt:93
$wgArticlePath
Definition: img_auth.php:45
$wgUseSquid
Enable/disable CDN.
randomUrlList($length)
Get an array of randomUrl()'s.
addDescription($text)
Set the description text.
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
getOption($name, $default=null)
Get an option, or return the default.
output($out, $channel=null)
Throw some output to the user.
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
randomUrl()
Return a random URL of the wiki.
Base class for benchmark scripts.
Definition: Benchmarker.php:36
error($err, $die=0)
Throw an error to the user.
$maintClass
randomTitle()
Create a random title string (not necessarily a Title object).
$wgServer
URL of the server.