3 * This script makes several 'set', 'incr' and 'get' requests on every
4 * memcached server and shows a report.
11 require_once( "Maintenance.php" );
13 class mcTest
extends Maintenance
{
14 public function __construct() {
15 parent
::__construct();
16 $this->mDescription
= "Makes several 'set', 'incr' and 'get' requests on every"
17 . " memcached server and shows a report";
18 $this->addParam( 'i', 'Number of iterations', false, true );
19 $this->addArgs( array( 'server' ) );
22 public function execute() {
23 global $wgMemCachedServers;
25 $iterations = $this->getOption( 'i', 100 );
27 $wgMemCachedServers = array( $this->getArg() );
29 foreach ( $wgMemCachedServers as $server ) {
30 $this->output( $server . " " );
31 $mcc = new MemCachedClientforWiki( array('persistant' => true) );
32 $mcc->set_servers( array( $server ) );
36 $time_start = $this->microtime_float();
37 for ( $i=1; $i<=$iterations; $i++
) {
38 if ( !is_null( $mcc->set( "test$i", $i ) ) ) {
42 for ( $i=1; $i<=$iterations; $i++
) {
43 if ( !is_null( $mcc->incr( "test$i", $i ) ) ) {
47 for ( $i=1; $i<=$iterations; $i++
) {
48 $value = $mcc->get( "test$i" );
49 if ( $value == $i*2 ) {
53 $exectime = $this->microtime_float() - $time_start;
55 $this->output( "set: $set incr: $incr get: $get time: $exectime\n" );
60 * Return microtime() as a float
63 private function microtime_float() {
64 list($usec, $sec) = explode(" ", microtime());
65 return ((float)$usec +
(float)$sec);
69 $maintClass = "mcTest";
70 require_once( DO_MAINTENANCE
);