Merge maintenance-work branch:
[lhc/web/wiklou.git] / maintenance / mctest.php
1 <?php
2 /**
3 * This script makes several 'set', 'incr' and 'get' requests on every
4 * memcached server and shows a report.
5 *
6 * $Id$
7 * @file
8 * @ingroup Maintenance
9 */
10
11 require_once( "Maintenance.php" );
12
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' ) );
20 }
21
22 public function execute() {
23 global $wgMemCachedServers;
24
25 $iterations = $this->getOption( 'i', 100 );
26 if( $this->hasArg() )
27 $wgMemCachedServers = array( $this->getArg() );
28
29 foreach ( $wgMemCachedServers as $server ) {
30 $this->output( $server . " " );
31 $mcc = new MemCachedClientforWiki( array('persistant' => true) );
32 $mcc->set_servers( array( $server ) );
33 $set = 0;
34 $incr = 0;
35 $get = 0;
36 $time_start = $this->microtime_float();
37 for ( $i=1; $i<=$iterations; $i++ ) {
38 if ( !is_null( $mcc->set( "test$i", $i ) ) ) {
39 $set++;
40 }
41 }
42 for ( $i=1; $i<=$iterations; $i++ ) {
43 if ( !is_null( $mcc->incr( "test$i", $i ) ) ) {
44 $incr++;
45 }
46 }
47 for ( $i=1; $i<=$iterations; $i++ ) {
48 $value = $mcc->get( "test$i" );
49 if ( $value == $i*2 ) {
50 $get++;
51 }
52 }
53 $exectime = $this->microtime_float() - $time_start;
54
55 $this->output( "set: $set incr: $incr get: $get time: $exectime\n" );
56 }
57 }
58
59 /**
60 * Return microtime() as a float
61 * @return float
62 */
63 private function microtime_float() {
64 list($usec, $sec) = explode(" ", microtime());
65 return ((float)$usec + (float)$sec);
66 }
67 }
68
69 $maintClass = "mcTest";
70 require_once( DO_MAINTENANCE );