f67c6c811d01b6d6df86d478778dfeb3a5ee712f
3 * Squid purge benchmark script
9 require_once( "Maintenance.php" );
11 class BenchmarkPurge
extends Maintenance
{
13 public function __construct() {
14 parent
::__construct();
15 $this->addParams( "count", "How many URLs to feed to Squid for purging", false, true );
16 $this->mDescription
= "Benchmark the Squid purge functions.";
19 public function execute() {
22 $this->error( "Squid purge benchmark doesn't do much without squid support on.\n". true );
24 $this->output( "There are " . count( $wgSquidServers ) . " defined squid servers:\n" );
25 if( $this->hasOption( 'count' ) ) {
26 $lengths = array( intval( $this->getOption('count') ) );
28 $lengths = array( 1, 10, 100 );
30 foreach( $lengths as $length ) {
31 $urls = $this->randomUrlList( $length );
32 $trial = $this->benchSquid( $urls );
33 $this->output( $trial . "\n" );
39 * Run a bunch of URLs through SquidUpdate::purge()
40 * to benchmark Squid response times.
41 * @param $urls array A bunch of URLs to purge
42 * @param $trials int How many times to run the test?
44 private function benchSquid( $urls, $trials = 1 ) {
46 for( $i = 0; $i < $trials; $i++
) {
47 SquidUpdate
::purge( $urls );
49 $delta = wfTime() - $start;
50 $pertrial = $delta / $trials;
51 $pertitle = $pertrial / count( $urls );
52 return sprintf( "%4d titles in %6.2fms (%6.2fms each)",
53 count( $urls ), $pertrial * 1000.0, $pertitle * 1000.0 );
57 * Get an array of randomUrl()'s.
58 * @param $length int How many urls to add to the array
60 private function randomUrlList( $length ) {
62 for( $i = 0; $i < $length; $i++
) {
63 $list[] = $this->randomUrl();
69 * Return a random URL of the wiki. Not necessarily an actual title in the
70 * database, but at least a URL that looks like one.
72 private function randomUrl() {
73 global $wgServer, $wgArticlePath;
74 return $wgServer . str_replace( '$1', $this->randomTitle(), $wgArticlePath );
78 * Create a random title string (not necessarily a Title object).
79 * For use with randomUrl().
81 private function randomTitle() {
83 $length = mt_rand( 1, 20 );
84 for( $i = 0; $i < $length; $i++
) {
85 $str .= chr( mt_rand( ord('a'), ord('z') ) );
87 return ucfirst( $str );
91 $maintClass = "BenchmarkPurge";
92 require_once( DO_MAINTENANCE
);