MediaWiki 1.43.1
benchmarkPurge.php
Go to the documentation of this file.
1<?php
24// @codeCoverageIgnoreStart
25require_once __DIR__ . '/../includes/Benchmarker.php';
26// @codeCoverageIgnoreEnd
27
29
35class BenchmarkPurge extends Benchmarker {
36 public function __construct() {
37 parent::__construct();
38 $this->addDescription( 'Benchmark the CDN purge functions.' );
39 }
40
41 public function execute() {
43
44 if ( !$wgUseCdn ) {
45 $this->error( "CDN purge benchmark doesn't do much without CDN support on." );
46 } else {
47 $this->output( "There are " . count( $wgCdnServers ) . " defined CDN servers:\n" );
48 if ( $this->hasOption( 'count' ) ) {
49 $lengths = [ intval( $this->getOption( 'count' ) ) ];
50 } else {
51 $lengths = [ 1, 10, 100 ];
52 }
53 foreach ( $lengths as $length ) {
54 $urls = $this->randomUrlList( $length );
55 $trial = $this->benchCdn( $urls );
56 $this->output( $trial . "\n" );
57 }
58 }
59 }
60
68 private function benchCdn( $urls, $trials = 1 ) {
69 $start = microtime( true );
70 for ( $i = 0; $i < $trials; $i++ ) {
71 CdnCacheUpdate::purge( $urls );
72 }
73 $delta = microtime( true ) - $start;
74 $pertrial = $delta / $trials;
75 $pertitle = $pertrial / count( $urls );
76
77 return sprintf( "%4d titles in %6.2fms (%6.2fms each)",
78 count( $urls ), $pertrial * 1000.0, $pertitle * 1000.0 );
79 }
80
86 private function randomUrlList( $length ) {
87 $list = [];
88 for ( $i = 0; $i < $length; $i++ ) {
89 $list[] = $this->randomUrl();
90 }
91
92 return $list;
93 }
94
100 private function randomUrl() {
102
103 return $wgServer . str_replace( '$1', $this->randomTitle(), $wgArticlePath );
104 }
105
111 private function randomTitle() {
112 $str = '';
113 $length = mt_rand( 1, 20 );
114 for ( $i = 0; $i < $length; $i++ ) {
115 $str .= chr( mt_rand( ord( 'a' ), ord( 'z' ) ) );
116 }
117
118 return ucfirst( $str );
119 }
120}
121
122// @codeCoverageIgnoreStart
123$maintClass = BenchmarkPurge::class;
124require_once RUN_MAINTENANCE_IF_MAIN;
125// @codeCoverageIgnoreEnd
$maintClass
Maintenance script that benchmarks CDN purge.
Handles purging the appropriate CDN objects given a list of URLs or Title instances.
$wgUseCdn
Config variable stub for the UseCdn setting, for use by phpdoc and IDEs.
$wgArticlePath
Config variable stub for the ArticlePath setting, for use by phpdoc and IDEs.
$wgServer
Config variable stub for the Server setting, for use by phpdoc and IDEs.
$wgCdnServers
Config variable stub for the CdnServers setting, for use by phpdoc and IDEs.