Remove some unused getting of non existent arguments
[lhc/web/wiklou.git] / maintenance / benchmarks / benchmarkPurge.php
1 <?php
2 /**
3 * Squid purge benchmark script
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup Maintenance
22 */
23
24 require_once( dirname( __FILE__ ) . '/Benchmarker.php' );
25
26 class BenchmarkPurge extends Benchmarker {
27
28 public function __construct() {
29 parent::__construct();
30 $this->mDescription = "Benchmark the Squid purge functions.";
31 }
32
33 public function execute() {
34 global $wgUseSquid, $wgSquidServers;
35 if ( !$wgUseSquid ) {
36 $this->error( "Squid purge benchmark doesn't do much without squid support on.", true );
37 } else {
38 $this->output( "There are " . count( $wgSquidServers ) . " defined squid servers:\n" );
39 if ( $this->hasOption( 'count' ) ) {
40 $lengths = array( intval( $this->getOption( 'count' ) ) );
41 } else {
42 $lengths = array( 1, 10, 100 );
43 }
44 foreach ( $lengths as $length ) {
45 $urls = $this->randomUrlList( $length );
46 $trial = $this->benchSquid( $urls );
47 $this->output( $trial . "\n" );
48 }
49 }
50 }
51
52 /**
53 * Run a bunch of URLs through SquidUpdate::purge()
54 * to benchmark Squid response times.
55 * @param $urls array A bunch of URLs to purge
56 * @param $trials int How many times to run the test?
57 * @return string
58 */
59 private function benchSquid( $urls, $trials = 1 ) {
60 $start = wfTime();
61 for ( $i = 0; $i < $trials; $i++ ) {
62 SquidUpdate::purge( $urls );
63 }
64 $delta = wfTime() - $start;
65 $pertrial = $delta / $trials;
66 $pertitle = $pertrial / count( $urls );
67 return sprintf( "%4d titles in %6.2fms (%6.2fms each)",
68 count( $urls ), $pertrial * 1000.0, $pertitle * 1000.0 );
69 }
70
71 /**
72 * Get an array of randomUrl()'s.
73 * @param $length int How many urls to add to the array
74 * @return array
75 */
76 private function randomUrlList( $length ) {
77 $list = array();
78 for ( $i = 0; $i < $length; $i++ ) {
79 $list[] = $this->randomUrl();
80 }
81 return $list;
82 }
83
84 /**
85 * Return a random URL of the wiki. Not necessarily an actual title in the
86 * database, but at least a URL that looks like one.
87 * @return string
88 */
89 private function randomUrl() {
90 global $wgServer, $wgArticlePath;
91 return $wgServer . str_replace( '$1', $this->randomTitle(), $wgArticlePath );
92 }
93
94 /**
95 * Create a random title string (not necessarily a Title object).
96 * For use with randomUrl().
97 * @return string
98 */
99 private function randomTitle() {
100 $str = '';
101 $length = mt_rand( 1, 20 );
102 for ( $i = 0; $i < $length; $i++ ) {
103 $str .= chr( mt_rand( ord( 'a' ), ord( 'z' ) ) );
104 }
105 return ucfirst( $str );
106 }
107 }
108
109 $maintClass = "BenchmarkPurge";
110 require_once( RUN_MAINTENANCE_IF_MAIN );