* kw (new), el
[mediawiki.git] / maintenance / benchmarkPurge.php
blob0ceb8445635a36b72dee55e12d73dcf41c2ae956
1 <?php
2 /**
3 * Squid purge benchmark script
4 * @addtogroup Maintenance
5 */
7 /** */
8 require_once( "commandLine.inc" );
10 /** @todo document */
11 function benchSquid( $urls, $trials = 1 ) {
12 $start = wfTime();
13 for( $i = 0; $i < $trials; $i++) {
14 SquidUpdate::purge( $urls );
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 );
23 /** @todo document */
24 function randomUrlList( $length ) {
25 $list = array();
26 for( $i = 0; $i < $length; $i++ ) {
27 $list[] = randomUrl();
29 return $list;
32 /** @todo document */
33 function randomUrl() {
34 global $wgServer, $wgArticlePath;
35 return $wgServer . str_replace( '$1', randomTitle(), $wgArticlePath );
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') ) );
45 return ucfirst( $str );
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 );
58 foreach( $lengths as $length ) {
59 $urls = randomUrlList( $length );
60 $trial = benchSquid( $urls );
61 print "$trial\n";