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