Revert r52336 "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 $optionsWithArgs = array( 'i' );
12
13 require_once('commandLine.inc');
14
15 function microtime_float()
16 {
17 list($usec, $sec) = explode(" ", microtime());
18 return ((float)$usec + (float)$sec);
19 }
20
21
22 #$wgDebugLogFile = '/dev/stdout';
23
24 if ( isset( $args[0] ) ) {
25 $wgMemCachedServers = array( $args[0] );
26 }
27 if ( isset( $options['i'] ) ) {
28 $iterations = $options['i'];
29 } else {
30 $iterations = 100;
31 }
32
33 foreach ( $wgMemCachedServers as $server ) {
34 print "$server ";
35 $mcc = new MemCachedClientforWiki( array('persistant' => true) );
36 $mcc->set_servers( array( $server ) );
37 $set = 0;
38 $incr = 0;
39 $get = 0;
40 $time_start=microtime_float();
41 for ( $i=1; $i<=$iterations; $i++ ) {
42 if ( !is_null( $mcc->set( "test$i", $i ) ) ) {
43 $set++;
44 }
45 }
46
47 for ( $i=1; $i<=$iterations; $i++ ) {
48 if ( !is_null( $mcc->incr( "test$i", $i ) ) ) {
49 $incr++;
50 }
51 }
52
53 for ( $i=1; $i<=$iterations; $i++ ) {
54 $value = $mcc->get( "test$i" );
55 if ( $value == $i*2 ) {
56 $get++;
57 }
58 }
59 $exectime=microtime_float()-$time_start;
60
61 print "set: $set incr: $incr get: $get time: $exectime\n";
62 }
63
64
65