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