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;
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
$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()
const CACHE_MEMCACHED
Definition Defines.php:113
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