MediaWiki
REL1_22
|
00001 <?php 00024 require_once __DIR__ . '/Benchmarker.php'; 00025 00031 class BenchmarkPurge extends Benchmarker { 00032 00033 public function __construct() { 00034 parent::__construct(); 00035 $this->mDescription = "Benchmark the Squid purge functions."; 00036 } 00037 00038 public function execute() { 00039 global $wgUseSquid, $wgSquidServers; 00040 if ( !$wgUseSquid ) { 00041 $this->error( "Squid purge benchmark doesn't do much without squid support on.", true ); 00042 } else { 00043 $this->output( "There are " . count( $wgSquidServers ) . " defined squid servers:\n" ); 00044 if ( $this->hasOption( 'count' ) ) { 00045 $lengths = array( intval( $this->getOption( 'count' ) ) ); 00046 } else { 00047 $lengths = array( 1, 10, 100 ); 00048 } 00049 foreach ( $lengths as $length ) { 00050 $urls = $this->randomUrlList( $length ); 00051 $trial = $this->benchSquid( $urls ); 00052 $this->output( $trial . "\n" ); 00053 } 00054 } 00055 } 00056 00064 private function benchSquid( $urls, $trials = 1 ) { 00065 $start = microtime( true ); 00066 for ( $i = 0; $i < $trials; $i++ ) { 00067 SquidUpdate::purge( $urls ); 00068 } 00069 $delta = microtime( true ) - $start; 00070 $pertrial = $delta / $trials; 00071 $pertitle = $pertrial / count( $urls ); 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 return $list; 00087 } 00088 00094 private function randomUrl() { 00095 global $wgServer, $wgArticlePath; 00096 return $wgServer . str_replace( '$1', $this->randomTitle(), $wgArticlePath ); 00097 } 00098 00104 private function randomTitle() { 00105 $str = ''; 00106 $length = mt_rand( 1, 20 ); 00107 for ( $i = 0; $i < $length; $i++ ) { 00108 $str .= chr( mt_rand( ord( 'a' ), ord( 'z' ) ) ); 00109 } 00110 return ucfirst( $str ); 00111 } 00112 } 00113 00114 $maintClass = "BenchmarkPurge"; 00115 require_once RUN_MAINTENANCE_IF_MAIN;