MediaWiki  1.23.6
mctest.php
Go to the documentation of this file.
1 <?php
25 require_once __DIR__ . '/Maintenance.php';
26 
33 class McTest extends Maintenance {
34  public function __construct() {
35  parent::__construct();
36  $this->mDescription = "Makes several 'set', 'incr' and 'get' requests on every"
37  . " memcached server and shows a report";
38  $this->addOption( 'i', 'Number of iterations', false, true );
39  $this->addOption( 'cache', 'Use servers from this $wgObjectCaches store', false, true );
40  $this->addArg( 'server[:port]', 'Memcached server to test, with optional port', false );
41  }
42 
43  public function execute() {
44  global $wgMainCacheType, $wgMemCachedTimeout, $wgObjectCaches;
45 
46  $cache = $this->getOption( 'cache' );
47  $iterations = $this->getOption( 'i', 100 );
48  if ( $cache ) {
49  if ( !isset( $wgObjectCaches[$cache] ) ) {
50  $this->error( "MediaWiki isn't configured with a cache named '$cache'", 1 );
51  }
52  $servers = $wgObjectCaches[$cache]['servers'];
53  } elseif ( $this->hasArg() ) {
54  $servers = array( $this->getArg() );
55  } elseif ( $wgMainCacheType === CACHE_MEMCACHED ) {
57  $servers = $wgMemCachedServers;
58  } elseif ( isset( $wgObjectCaches[$wgMainCacheType]['servers'] ) ) {
59  $servers = $wgObjectCaches[$wgMainCacheType]['servers'];
60  } else {
61  $this->error( "MediaWiki isn't configured for Memcached usage", 1 );
62  }
63 
64  # find out the longest server string to nicely align output later on
65  $maxSrvLen = $servers ? max( array_map( 'strlen', $servers ) ) : 0;
66 
67  foreach ( $servers as $server ) {
68  $this->output(
69  str_pad( $server, $maxSrvLen ),
70  $server # output channel
71  );
72 
74  'persistant' => true,
75  'timeout' => $wgMemCachedTimeout
76  ) );
77  $mcc->set_servers( array( $server ) );
78  $set = 0;
79  $incr = 0;
80  $get = 0;
81  $time_start = $this->microtime_float();
82  for ( $i = 1; $i <= $iterations; $i++ ) {
83  if ( $mcc->set( "test$i", $i ) ) {
84  $set++;
85  }
86  }
87  for ( $i = 1; $i <= $iterations; $i++ ) {
88  if ( !is_null( $mcc->incr( "test$i", $i ) ) ) {
89  $incr++;
90  }
91  }
92  for ( $i = 1; $i <= $iterations; $i++ ) {
93  $value = $mcc->get( "test$i" );
94  if ( $value == $i * 2 ) {
95  $get++;
96  }
97  }
98  $exectime = $this->microtime_float() - $time_start;
99 
100  $this->output( " set: $set incr: $incr get: $get time: $exectime", $server );
101  }
102  }
103 
108  private function microtime_float() {
109  list( $usec, $sec ) = explode( " ", microtime() );
110  return ( (float)$usec + (float)$sec );
111  }
112 }
113 
114 $maintClass = "McTest";
115 require_once RUN_MAINTENANCE_IF_MAIN;
McTest\__construct
__construct()
Default constructor.
Definition: mctest.php:34
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
CACHE_MEMCACHED
const CACHE_MEMCACHED
Definition: Defines.php:114
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false)
Add a parameter to the script.
Definition: Maintenance.php:169
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
Maintenance\hasArg
hasArg( $argId=0)
Does a given argument exist?
Definition: Maintenance.php:236
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: maintenance.txt:39
$mcc
if( $help) $mcc
Definition: mcc.php:38
McTest
Maintenance script that makes several 'set', 'incr' and 'get' requests on every memcached server and ...
Definition: mctest.php:33
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
$wgMemCachedServers
$wgMemCachedServers
Definition: memcached.txt:64
list
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
$value
$value
Definition: styleTest.css.php:45
$maintClass
$maintClass
Definition: mctest.php:114
MemCachedClientforWiki
Definition: MemcachedClient.php:1237
Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition: Maintenance.php:191
$cache
$cache
Definition: mcc.php:32
Maintenance\addArg
addArg( $arg, $description, $required=true)
Add some args that are needed.
Definition: Maintenance.php:207
$wgMainCacheType
CACHE_MEMCACHED $wgMainCacheType
Definition: memcached.txt:63
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
McTest\microtime_float
microtime_float()
Return microtime() as a float.
Definition: mctest.php:108
Maintenance\error
error( $err, $die=0)
Throw an error to the user.
Definition: Maintenance.php:333
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:314
Maintenance\getArg
getArg( $argId=0, $default=null)
Get an argument.
Definition: Maintenance.php:246
McTest\execute
execute()
Do the actual work.
Definition: mctest.php:43