3 * Squid purge benchmark script
10 require_once( "commandLine.inc" );
13 * Run a bunch of URLs through SquidUpdate::purge()
14 * to benchmark Squid response times.
15 * @param $urls array A bunch of URLs to purge
16 * @param $trials int How many times to run the test?
18 function benchSquid( $urls, $trials = 1 ) {
20 for( $i = 0; $i < $trials; $i++) {
21 SquidUpdate::purge( $urls );
23 $delta = wfTime() - $start;
24 $pertrial = $delta / $trials;
25 $pertitle = $pertrial / count( $urls );
26 return sprintf( "%4d titles in %6.2fms (%6.2fms each)",
27 count( $urls ), $pertrial * 1000.0, $pertitle * 1000.0 );
31 * Get an array of randomUrl()'s.
32 * @param $length int How many urls to add to the array
34 function randomUrlList( $length ) {
36 for( $i = 0; $i < $length; $i++ ) {
37 $list[] = randomUrl();
43 * Return a random URL of the wiki. Not necessarily an actual title in the
44 * database, but at least a URL that looks like one.
46 function randomUrl() {
47 global $wgServer, $wgArticlePath;
48 return $wgServer . str_replace( '$1', randomTitle(), $wgArticlePath );
52 * Create a random title string (not necessarily a Title object).
53 * For use with randomUrl().
55 function randomTitle() {
57 $length = mt_rand( 1, 20 );
58 for( $i = 0; $i < $length; $i++ ) {
59 $str .= chr( mt_rand( ord('a'), ord('z') ) );
61 return ucfirst( $str );
65 wfDie( "Squid purge benchmark doesn't do much without squid support on.\n" );
67 printf( "There are %d defined squid servers:\n", count( $wgSquidServers ) );
68 #echo implode( "\n", $wgSquidServers ) . "\n";
69 if( isset( $options['count'] ) ) {
70 $lengths = array( intval( $options['count'] ) );
72 $lengths = array( 1, 10, 100 );
74 foreach( $lengths as $length ) {
75 $urls = randomUrlList( $length );
76 $trial = benchSquid( $urls );