MediaWiki
REL1_20
|
00001 <?php 00025 require_once( __DIR__ . '/Maintenance.php' ); 00026 00033 class mcTest extends Maintenance { 00034 public function __construct() { 00035 parent::__construct(); 00036 $this->mDescription = "Makes several 'set', 'incr' and 'get' requests on every" 00037 . " memcached server and shows a report"; 00038 $this->addOption( 'i', 'Number of iterations', false, true ); 00039 $this->addArg( 'server[:port]', 'Memcached server to test, with optional port', false ); 00040 } 00041 00042 public function execute() { 00043 global $wgMemCachedServers, $wgMemCachedTimeout; 00044 00045 $iterations = $this->getOption( 'i', 100 ); 00046 if ( $this->hasArg() ) { 00047 $wgMemCachedServers = array( $this->getArg() ); 00048 } 00049 00050 foreach ( $wgMemCachedServers as $server ) { 00051 $this->output( $server . " ", $server ); 00052 $mcc = new MemCachedClientforWiki( array( 00053 'persistant' => true, 00054 'timeout' => $wgMemCachedTimeout 00055 ) ); 00056 $mcc->set_servers( array( $server ) ); 00057 $set = 0; 00058 $incr = 0; 00059 $get = 0; 00060 $time_start = $this->microtime_float(); 00061 for ( $i = 1; $i <= $iterations; $i++ ) { 00062 if ( !is_null( $mcc->set( "test$i", $i ) ) ) { 00063 $set++; 00064 } 00065 } 00066 for ( $i = 1; $i <= $iterations; $i++ ) { 00067 if ( !is_null( $mcc->incr( "test$i", $i ) ) ) { 00068 $incr++; 00069 } 00070 } 00071 for ( $i = 1; $i <= $iterations; $i++ ) { 00072 $value = $mcc->get( "test$i" ); 00073 if ( $value == $i * 2 ) { 00074 $get++; 00075 } 00076 } 00077 $exectime = $this->microtime_float() - $time_start; 00078 00079 $this->output( "set: $set incr: $incr get: $get time: $exectime", $server ); 00080 } 00081 } 00082 00087 private function microtime_float() { 00088 list( $usec, $sec ) = explode( " ", microtime() ); 00089 return ( (float)$usec + (float)$sec ); 00090 } 00091 } 00092 00093 $maintClass = "mcTest"; 00094 require_once( RUN_MAINTENANCE_IF_MAIN );