MediaWiki REL1_31
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() ) {
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->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.
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()
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling output() to send it all. It could be easily changed to send incrementally if that becomes useful
const CACHE_MEMCACHED
Definition Defines.php:114
require_once RUN_MAINTENANCE_IF_MAIN
if( $help) $mcc
Definition mcc.php:39
$cache
Definition mcc.php:33
$maintClass
Definition mctest.php:105
$wgMemCachedServers
Definition memcached.txt:64
CACHE_MEMCACHED $wgMainCacheType
Definition memcached.txt:63