25require_once __DIR__ .
'/Maintenance.php';
35 parent::__construct();
37 "Makes several operation requests on every cache server and shows a report.\n" .
38 "This tests both per-key and batched *Multi() methods as well as WRITE_BACKGROUND.\n" .
39 "\"IB\" means \"immediate blocking\" and \"DB\" means \"deferred blocking.\""
41 $this->
addOption(
'i',
'Number of iterations',
false,
true );
42 $this->
addOption(
'cache',
'Use servers from this $wgObjectCaches store',
false,
true );
43 $this->
addOption(
'driver',
'Either "php" or "pecl"',
false,
true );
44 $this->
addArg(
'server[:port]',
'Memcached server to test, with optional port',
false );
50 $memcachedTypes = [
CACHE_MEMCACHED,
'memcached-php',
'memcached-pecl' ];
53 $iterations = $this->
getOption(
'i', 100 );
56 $this->
fatalError(
"MediaWiki isn't configured with a cache named '$cache'" );
59 } elseif ( $this->
hasArg( 0 ) ) {
60 $servers = [ $this->
getArg( 0 ) ];
67 $this->
fatalError(
"MediaWiki isn't configured for Memcached usage" );
70 # find out the longest server string to nicely align output later on
71 $maxSrvLen = $servers ? max( array_map(
'strlen', $servers ) ) : 0;
74 if (
$type ===
'php' ) {
75 $class = MemcachedPhpBagOStuff::class;
76 } elseif (
$type ===
'pecl' ) {
77 $class = MemcachedPeclBagOStuff::class;
79 $this->
fatalError(
"Invalid driver type '$type'" );
82 $this->
output(
"Warming up connections to cache servers..." );
84 foreach ( $servers as $server ) {
86 $mccByServer[$server] =
new $class( [
87 'servers' => [ $server ],
89 'allow_tcp_nagle_delay' =>
false,
92 $mccByServer[$server]->get(
'key' );
95 $this->
output(
"Single and batched operation profiling/test results:\n" );
98 for ( $i = 1; $i <= $iterations; $i++ ) {
99 $valueByKey[
"test$i"] =
'S' . str_pad( $i, 2048 );
102 foreach ( $mccByServer as $server =>
$mcc ) {
103 $this->
output( str_pad( $server, $maxSrvLen ) .
"\n" );
121 $i = count( $valueByKey );
122 $keys = array_keys( $valueByKey );
127 $time_start = microtime(
true );
128 foreach (
$keys as $key ) {
129 if (
$mcc->add( $key, $i ) ) {
133 $addMs = intval( 1e3 * ( microtime(
true ) - $time_start ) );
135 $time_start = microtime(
true );
136 foreach (
$keys as $key ) {
137 if (
$mcc->set( $key, $i ) ) {
141 $setMs = intval( 1e3 * ( microtime(
true ) - $time_start ) );
143 $time_start = microtime(
true );
144 foreach (
$keys as $key ) {
145 if (
$mcc->incr( $key, $i ) !==
null ) {
149 $incrMs = intval( 1e3 * ( microtime(
true ) - $time_start ) );
151 $time_start = microtime(
true );
152 foreach (
$keys as $key ) {
153 $value =
$mcc->get( $key );
154 if ( $value == $i * 2 ) {
158 $getMs = intval( 1e3 * ( microtime(
true ) - $time_start ) );
160 $time_start = microtime(
true );
161 foreach (
$keys as $key ) {
162 if (
$mcc->delete( $key ) ) {
166 $delMs = intval( 1e3 * ( microtime(
true ) - $time_start ) );
169 " add: $add/$i {$addMs}ms " .
170 "set: $set/$i {$setMs}ms " .
171 "incr: $incr/$i {$incrMs}ms " .
172 "get: $get/$i ({$getMs}ms) " .
173 "delete: $delete/$i ({$delMs}ms)\n"
182 $keys = array_keys( $valueByKey );
183 $iterations = count( $valueByKey );
185 $time_start = microtime(
true );
186 $mSetOk =
$mcc->setMulti( $valueByKey ) ?
'✓' :
'✗';
187 $mSetMs = intval( 1e3 * ( microtime(
true ) - $time_start ) );
189 $time_start = microtime(
true );
191 $mGetMs = intval( 1e3 * ( microtime(
true ) - $time_start ) );
193 foreach ( $found as $key => $value ) {
194 $mGetOk += ( $value === $valueByKey[$key] );
197 $time_start = microtime(
true );
198 $mChangeTTLOk =
$mcc->changeTTLMulti(
$keys, 3600 ) ?
'✓' :
'✗';
199 $mChangeTTTMs = intval( 1e3 * ( microtime(
true ) - $time_start ) );
201 $time_start = microtime(
true );
202 $mDelOk =
$mcc->deleteMulti(
$keys ) ?
'✓' :
'✗';
203 $mDelMs = intval( 1e3 * ( microtime(
true ) - $time_start ) );
206 " setMulti (IB): $mSetOk {$mSetMs}ms " .
207 "getMulti (IB): $mGetOk/$iterations {$mGetMs}ms " .
208 "changeTTLMulti (IB): $mChangeTTLOk {$mChangeTTTMs}ms " .
209 "deleteMulti (IB): $mDelOk {$mDelMs}ms\n"
218 $keys = array_keys( $valueByKey );
219 $iterations = count( $valueByKey );
220 $flags = $mcc::WRITE_BACKGROUND;
222 $time_start = microtime(
true );
223 $mSetOk =
$mcc->setMulti( $valueByKey, 0, $flags ) ?
'✓' :
'✗';
224 $mSetMs = intval( 1e3 * ( microtime(
true ) - $time_start ) );
226 $time_start = microtime(
true );
228 $mGetMs = intval( 1e3 * ( microtime(
true ) - $time_start ) );
230 foreach ( $found as $key => $value ) {
231 $mGetOk += ( $value === $valueByKey[$key] );
234 $time_start = microtime(
true );
235 $mChangeTTLOk =
$mcc->changeTTLMulti(
$keys, 3600, $flags ) ?
'✓' :
'✗';
236 $mChangeTTTMs = intval( 1e3 * ( microtime(
true ) - $time_start ) );
238 $time_start = microtime(
true );
239 $mDelOk =
$mcc->deleteMulti(
$keys, $flags ) ?
'✓' :
'✗';
240 $mDelMs = intval( 1e3 * ( microtime(
true ) - $time_start ) );
243 " setMulti (DB): $mSetOk {$mSetMs}ms " .
244 "getMulti (DB): $mGetOk/$iterations {$mGetMs}ms " .
245 "changeTTLMulti (DB): $mChangeTTLOk {$mChangeTTTMs}ms " .
246 "deleteMulti (DB): $mDelOk {$mDelMs}ms\n"
252require_once RUN_MAINTENANCE_IF_MAIN;
$wgObjectCaches
Advanced object cache configuration.
$wgMainCacheType
Main cache type.
$wgMemCachedTimeout
Read/write timeout for MemCached server communication, in microseconds.
$wgMemCachedServers
The list of MemCached servers and port numbers.
Class representing a cache/ephemeral data store.
get( $key, $flags=0)
Get an item with the given key.
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 ...
benchmarkMultiKeyOpsImmediateBlocking(BagOStuff $mcc, array $valueByKey)
benchmarkMultiKeyOpsDeferredBlocking(BagOStuff $mcc, array $valueByKey)
__construct()
Default constructor.
execute()
Do the actual work.
benchmarkSingleKeyOps(BagOStuff $mcc, array $valueByKey)