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