MediaWiki  REL1_24
benchmarkPurge.php
Go to the documentation of this file.
00001 <?php
00024 require_once __DIR__ . '/Benchmarker.php';
00025 
00031 class BenchmarkPurge extends Benchmarker {
00032     public function __construct() {
00033         parent::__construct();
00034         $this->mDescription = "Benchmark the Squid purge functions.";
00035     }
00036 
00037     public function execute() {
00038         global $wgUseSquid, $wgSquidServers;
00039         if ( !$wgUseSquid ) {
00040             $this->error( "Squid purge benchmark doesn't do much without squid support on.", true );
00041         } else {
00042             $this->output( "There are " . count( $wgSquidServers ) . " defined squid servers:\n" );
00043             if ( $this->hasOption( 'count' ) ) {
00044                 $lengths = array( intval( $this->getOption( 'count' ) ) );
00045             } else {
00046                 $lengths = array( 1, 10, 100 );
00047             }
00048             foreach ( $lengths as $length ) {
00049                 $urls = $this->randomUrlList( $length );
00050                 $trial = $this->benchSquid( $urls );
00051                 $this->output( $trial . "\n" );
00052             }
00053         }
00054     }
00055 
00063     private function benchSquid( $urls, $trials = 1 ) {
00064         $start = microtime( true );
00065         for ( $i = 0; $i < $trials; $i++ ) {
00066             SquidUpdate::purge( $urls );
00067         }
00068         $delta = microtime( true ) - $start;
00069         $pertrial = $delta / $trials;
00070         $pertitle = $pertrial / count( $urls );
00071 
00072         return sprintf( "%4d titles in %6.2fms (%6.2fms each)",
00073             count( $urls ), $pertrial * 1000.0, $pertitle * 1000.0 );
00074     }
00075 
00081     private function randomUrlList( $length ) {
00082         $list = array();
00083         for ( $i = 0; $i < $length; $i++ ) {
00084             $list[] = $this->randomUrl();
00085         }
00086 
00087         return $list;
00088     }
00089 
00095     private function randomUrl() {
00096         global $wgServer, $wgArticlePath;
00097 
00098         return $wgServer . str_replace( '$1', $this->randomTitle(), $wgArticlePath );
00099     }
00100 
00106     private function randomTitle() {
00107         $str = '';
00108         $length = mt_rand( 1, 20 );
00109         for ( $i = 0; $i < $length; $i++ ) {
00110             $str .= chr( mt_rand( ord( 'a' ), ord( 'z' ) ) );
00111         }
00112 
00113         return ucfirst( $str );
00114     }
00115 }
00116 
00117 $maintClass = "BenchmarkPurge";
00118 require_once RUN_MAINTENANCE_IF_MAIN;