MediaWiki  1.30.0
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->addDescription( "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() {
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 = [ $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 
73  $mcc = new MemcachedClient( [
74  'persistant' => true,
75  'timeout' => $wgMemCachedTimeout
76  ] );
77  $mcc->set_servers( [ $server ] );
78  $set = 0;
79  $incr = 0;
80  $get = 0;
81  $time_start = microtime( true );
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 = microtime( true ) - $time_start;
99 
100  $this->output( " set: $set incr: $incr get: $get time: $exectime", $server );
101  }
102  }
103 }
104 
105 $maintClass = "McTest";
106 require_once RUN_MAINTENANCE_IF_MAIN;
McTest\__construct
__construct()
Default constructor.
Definition: mctest.php:34
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:287
CACHE_MEMCACHED
const CACHE_MEMCACHED
Definition: Defines.php:105
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:296
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:39
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
MemcachedClient
memcached client class implemented using (p)fsockopen()
Definition: MemcachedClient.php:79
McTest
Maintenance script that makes several 'set', 'incr' and 'get' requests on every memcached server and ...
Definition: mctest.php:33
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
Definition: Maintenance.php:215
$wgObjectCaches
$wgObjectCaches
Advanced object cache configuration.
Definition: DefaultSettings.php:2294
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
$wgMemCachedTimeout
$wgMemCachedTimeout
Read/write timeout for MemCached server communication, in microseconds.
Definition: DefaultSettings.php:2466
$value
$value
Definition: styleTest.css.php:45
$maintClass
$maintClass
Definition: mctest.php:105
Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition: Maintenance.php:250
$cache
$cache
Definition: mcc.php:33
Maintenance\addArg
addArg( $arg, $description, $required=true)
Add some args that are needed.
Definition: Maintenance.php:267
$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
Maintenance\error
error( $err, $die=0)
Throw an error to the user.
Definition: Maintenance.php:392
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:373
Maintenance\getArg
getArg( $argId=0, $default=null)
Get an argument.
Definition: Maintenance.php:306
McTest\execute
execute()
Do the actual work.
Definition: mctest.php:43