]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - maintenance/benchmarkPurge.php
MediaWiki 1.11.0
[autoinstallsdev/mediawiki.git] / maintenance / benchmarkPurge.php
1 <?php
2 /**
3  * Squid purge benchmark script
4  * @addtogroup Maintenance
5  */
6
7 /** */
8 require_once( "commandLine.inc" );
9
10 /** @todo document */
11 function benchSquid( $urls, $trials = 1 ) {
12         $start = wfTime();
13         for( $i = 0; $i < $trials; $i++) {
14                 SquidUpdate::purge( $urls );
15         }
16         $delta = wfTime() - $start;
17         $pertrial = $delta / $trials;
18         $pertitle = $pertrial / count( $urls );
19         return sprintf( "%4d titles in %6.2fms (%6.2fms each)",
20                 count( $urls ), $pertrial * 1000.0, $pertitle * 1000.0 );
21 }
22
23 /** @todo document */
24 function randomUrlList( $length ) {
25         $list = array();
26         for( $i = 0; $i < $length; $i++ ) {
27                 $list[] = randomUrl();
28         }
29         return $list;
30 }
31
32 /** @todo document */
33 function randomUrl() {
34         global $wgServer, $wgArticlePath;
35         return $wgServer . str_replace( '$1', randomTitle(), $wgArticlePath );
36 }
37
38 /** @todo document */
39 function randomTitle() {
40         $str = '';
41         $length = mt_rand( 1, 20 );
42         for( $i = 0; $i < $length; $i++ ) {
43                 $str .= chr( mt_rand( ord('a'), ord('z') ) );
44         }
45         return ucfirst( $str );
46 }
47
48 if( !$wgUseSquid ) {
49         wfDie( "Squid purge benchmark doesn't do much without squid support on.\n" );
50 } else {
51         printf( "There are %d defined squid servers:\n", count( $wgSquidServers ) );
52         #echo implode( "\n", $wgSquidServers ) . "\n";
53         if( isset( $options['count'] ) ) {
54                 $lengths = array( intval( $options['count'] ) );
55         } else {
56                 $lengths = array( 1, 10, 100 );
57         }
58         foreach( $lengths as $length ) {
59                 $urls = randomUrlList( $length );
60                 $trial = benchSquid( $urls );
61                 print "$trial\n";
62         }
63 }