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