Merge "Added result properties to action=paraminfo"
[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 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
20 *
21 * @ingroup Maintenance
22 */
23
24 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
25
26 class mcTest extends Maintenance {
27 public function __construct() {
28 parent::__construct();
29 $this->mDescription = "Makes several 'set', 'incr' and 'get' requests on every"
30 . " memcached server and shows a report";
31 $this->addOption( 'i', 'Number of iterations', false, true );
32 $this->addArg( 'server[:port]', 'Memcached server to test, with optional port', false );
33 }
34
35 public function execute() {
36 global $wgMemCachedServers, $wgMemCachedTimeout;
37
38 $iterations = $this->getOption( 'i', 100 );
39 if ( $this->hasArg() ) {
40 $wgMemCachedServers = array( $this->getArg() );
41 }
42
43 foreach ( $wgMemCachedServers as $server ) {
44 $this->output( $server . " ", $server );
45 $mcc = new MemCachedClientforWiki( array(
46 'persistant' => true,
47 'timeout' => $wgMemCachedTimeout
48 ) );
49 $mcc->set_servers( array( $server ) );
50 $set = 0;
51 $incr = 0;
52 $get = 0;
53 $time_start = $this->microtime_float();
54 for ( $i = 1; $i <= $iterations; $i++ ) {
55 if ( !is_null( $mcc->set( "test$i", $i ) ) ) {
56 $set++;
57 }
58 }
59 for ( $i = 1; $i <= $iterations; $i++ ) {
60 if ( !is_null( $mcc->incr( "test$i", $i ) ) ) {
61 $incr++;
62 }
63 }
64 for ( $i = 1; $i <= $iterations; $i++ ) {
65 $value = $mcc->get( "test$i" );
66 if ( $value == $i * 2 ) {
67 $get++;
68 }
69 }
70 $exectime = $this->microtime_float() - $time_start;
71
72 $this->output( "set: $set incr: $incr get: $get time: $exectime", $server );
73 }
74 }
75
76 /**
77 * Return microtime() as a float
78 * @return float
79 */
80 private function microtime_float() {
81 list( $usec, $sec ) = explode( " ", microtime() );
82 return ( (float)$usec + (float)$sec );
83 }
84 }
85
86 $maintClass = "mcTest";
87 require_once( RUN_MAINTENANCE_IF_MAIN );