MediaWiki REL1_33
mctest.php
Go to the documentation of this file.
1<?php
25require_once __DIR__ . '/Maintenance.php';
26
33class 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 ) {
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
105$maintClass = McTest::class;
106require_once RUN_MAINTENANCE_IF_MAIN;
$wgObjectCaches
Advanced object cache configuration.
$wgMemCachedTimeout
Read/write timeout for MemCached server communication, in microseconds.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
addArg( $arg, $description, $required=true)
Add some args that are needed.
output( $out, $channel=null)
Throw some output to the user.
hasArg( $argId=0)
Does a given argument exist?
getArg( $argId=0, $default=null)
Get an argument.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Maintenance script that makes several 'set', 'incr' and 'get' requests on every memcached server and ...
Definition mctest.php:33
__construct()
Default constructor.
Definition mctest.php:34
execute()
Do the actual work.
Definition mctest.php:43
memcached client class implemented using (p)fsockopen()
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
const CACHE_MEMCACHED
Definition Defines.php:113
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
require_once RUN_MAINTENANCE_IF_MAIN
if( $help) $mcc
Definition mcc.php:39
$cache
Definition mcc.php:33
$maintClass
Definition mctest.php:105
CACHE_MEMCACHED $wgMainCacheType
Definition memcached.txt:63
$wgMemCachedServers
Definition memcached.txt:64