MediaWiki REL1_31
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;
$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 SquidUpdate::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.
hasOption( $name)
Checks to see if a particular param 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.
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling output() to send it all. It could be easily changed to send incrementally if that becomes useful
when a variable name is used in a it is silently declared as a new local masking the global
Definition design.txt:95
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
$wgArticlePath
Definition img_auth.php:45
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:37
require_once RUN_MAINTENANCE_IF_MAIN