3 /* Squid purge benchmark script */
5 require_once( "commandLine.inc" );
7 function benchSquid( $urls, $trials = 1 ) {
9 for( $i = 0; $i < $trials; $i++
) {
10 SquidUpdate
::purge( $urls );
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 );
19 function randomUrlList( $length ) {
21 for( $i = 0; $i < $length; $i++
) {
22 $list[] = randomUrl();
27 function randomUrl() {
28 global $wgServer, $wgArticlePath;
29 return $wgServer . str_replace( '$1', randomTitle(), $wgArticlePath );
32 function randomTitle() {
34 $length = mt_rand( 1, 20 );
35 for( $i = 0; $i < $length; $i++
) {
36 $str .= chr( mt_rand( ord('a'), ord('z') ) );
38 return ucfirst( $str );
42 die( "Squid purge benchmark doesn't do much without squid support on.\n" );
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 );