MediaWiki
REL1_21
|
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->addOption( 'cache', 'Use servers from this $wgObjectCaches store', false, true ); 00040 $this->addArg( 'server[:port]', 'Memcached server to test, with optional port', false ); 00041 } 00042 00043 public function execute() { 00044 global $wgMainCacheType, $wgMemCachedTimeout, $wgObjectCaches; 00045 00046 $cache = $this->getOption( 'cache' ); 00047 $iterations = $this->getOption( 'i', 100 ); 00048 if ( $cache ) { 00049 if ( !isset( $wgObjectCaches[$cache] ) ) { 00050 $this->error( "MediaWiki isn't configured with a cache named '$cache'", 1 ); 00051 } 00052 $servers = $wgObjectCaches[$cache]['servers']; 00053 } elseif ( $this->hasArg() ) { 00054 $servers = array( $this->getArg() ); 00055 } elseif ( $wgMainCacheType === CACHE_MEMCACHED ) { 00056 global $wgMemCachedServers; 00057 $servers = $wgMemCachedServers ; 00058 } elseif ( isset( $wgObjectCaches[$wgMainCacheType]['servers'] ) ) { 00059 $servers = $wgObjectCaches[$wgMainCacheType]['servers']; 00060 } else { 00061 $this->error( "MediaWiki isn't configured for Memcached usage", 1 ); 00062 } 00063 00064 foreach ( $servers as $server ) { 00065 $this->output( $server . " ", $server ); 00066 $mcc = new MemCachedClientforWiki( array( 00067 'persistant' => true, 00068 'timeout' => $wgMemCachedTimeout 00069 ) ); 00070 $mcc->set_servers( array( $server ) ); 00071 $set = 0; 00072 $incr = 0; 00073 $get = 0; 00074 $time_start = $this->microtime_float(); 00075 for ( $i = 1; $i <= $iterations; $i++ ) { 00076 if ( !is_null( $mcc->set( "test$i", $i ) ) ) { 00077 $set++; 00078 } 00079 } 00080 for ( $i = 1; $i <= $iterations; $i++ ) { 00081 if ( !is_null( $mcc->incr( "test$i", $i ) ) ) { 00082 $incr++; 00083 } 00084 } 00085 for ( $i = 1; $i <= $iterations; $i++ ) { 00086 $value = $mcc->get( "test$i" ); 00087 if ( $value == $i * 2 ) { 00088 $get++; 00089 } 00090 } 00091 $exectime = $this->microtime_float() - $time_start; 00092 00093 $this->output( "set: $set incr: $incr get: $get time: $exectime", $server ); 00094 } 00095 } 00096 00101 private function microtime_float() { 00102 list( $usec, $sec ) = explode( " ", microtime() ); 00103 return ( (float)$usec + (float)$sec ); 00104 } 00105 } 00106 00107 $maintClass = "mcTest"; 00108 require_once( RUN_MAINTENANCE_IF_MAIN );