MediaWiki
REL1_19
|
00001 <?php 00024 require_once( dirname( __FILE__ ) . '/Benchmarker.php' ); 00025 00026 class BenchmarkPurge extends Benchmarker { 00027 00028 public function __construct() { 00029 parent::__construct(); 00030 $this->mDescription = "Benchmark the Squid purge functions."; 00031 } 00032 00033 public function execute() { 00034 global $wgUseSquid, $wgSquidServers; 00035 if ( !$wgUseSquid ) { 00036 $this->error( "Squid purge benchmark doesn't do much without squid support on.", true ); 00037 } else { 00038 $this->output( "There are " . count( $wgSquidServers ) . " defined squid servers:\n" ); 00039 if ( $this->hasOption( 'count' ) ) { 00040 $lengths = array( intval( $this->getOption( 'count' ) ) ); 00041 } else { 00042 $lengths = array( 1, 10, 100 ); 00043 } 00044 foreach ( $lengths as $length ) { 00045 $urls = $this->randomUrlList( $length ); 00046 $trial = $this->benchSquid( $urls ); 00047 $this->output( $trial . "\n" ); 00048 } 00049 } 00050 } 00051 00059 private function benchSquid( $urls, $trials = 1 ) { 00060 $start = wfTime(); 00061 for ( $i = 0; $i < $trials; $i++ ) { 00062 SquidUpdate::purge( $urls ); 00063 } 00064 $delta = wfTime() - $start; 00065 $pertrial = $delta / $trials; 00066 $pertitle = $pertrial / count( $urls ); 00067 return sprintf( "%4d titles in %6.2fms (%6.2fms each)", 00068 count( $urls ), $pertrial * 1000.0, $pertitle * 1000.0 ); 00069 } 00070 00076 private function randomUrlList( $length ) { 00077 $list = array(); 00078 for ( $i = 0; $i < $length; $i++ ) { 00079 $list[] = $this->randomUrl(); 00080 } 00081 return $list; 00082 } 00083 00089 private function randomUrl() { 00090 global $wgServer, $wgArticlePath; 00091 return $wgServer . str_replace( '$1', $this->randomTitle(), $wgArticlePath ); 00092 } 00093 00099 private function randomTitle() { 00100 $str = ''; 00101 $length = mt_rand( 1, 20 ); 00102 for ( $i = 0; $i < $length; $i++ ) { 00103 $str .= chr( mt_rand( ord( 'a' ), ord( 'z' ) ) ); 00104 } 00105 return ucfirst( $str ); 00106 } 00107 } 00108 00109 $maintClass = "BenchmarkPurge"; 00110 require_once( RUN_MAINTENANCE_IF_MAIN );