MediaWiki  REL1_33
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->fatalError( "MediaWiki isn't configured with a cache named '$cache'" );
51  }
52  $servers = $wgObjectCaches[$cache]['servers'];
53  } elseif ( $this->hasArg( 0 ) ) {
54  $servers = [ $this->getArg( 0 ) ];
55  } elseif ( $wgMainCacheType === CACHE_MEMCACHED ) {
56  global $wgMemCachedServers;
57  $servers = $wgMemCachedServers;
58  } elseif ( isset( $wgObjectCaches[$wgMainCacheType]['servers'] ) ) {
59  $servers = $wgObjectCaches[$wgMainCacheType]['servers'];
60  } else {
61  $this->fatalError( "MediaWiki isn't configured for Memcached usage" );
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 
106 require_once RUN_MAINTENANCE_IF_MAIN;
McTest\__construct
__construct()
Default constructor.
Definition: mctest.php:34
Maintenance\fatalError
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Definition: Maintenance.php:485
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:329
CACHE_MEMCACHED
const CACHE_MEMCACHED
Definition: Defines.php:113
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:338
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:37
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:248
$wgObjectCaches
$wgObjectCaches
Advanced object cache configuration.
Definition: DefaultSettings.php:2386
$wgMemCachedServers
$wgMemCachedServers
Definition: memcached.txt:64
$wgMemCachedTimeout
$wgMemCachedTimeout
Read/write timeout for MemCached server communication, in microseconds.
Definition: DefaultSettings.php:2544
$value
$value
Definition: styleTest.css.php:49
$maintClass
$maintClass
Definition: mctest.php:105
Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition: Maintenance.php:283
$cache
$cache
Definition: mcc.php:33
$wgMainCacheType
CACHE_MEMCACHED $wgMainCacheType
Definition: memcached.txt:63
Maintenance\addArg
addArg( $arg, $description, $required=true)
Add some args that are needed.
Definition: Maintenance.php:300
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:22
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:434
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:56
Maintenance\getArg
getArg( $argId=0, $default=null)
Get an argument.
Definition: Maintenance.php:352
McTest\execute
execute()
Do the actual work.
Definition: mctest.php:43