public function execute() { global $wgMainCacheType, $wgMemCachedTimeout, $wgObjectCaches; $cache = $this->getOption( 'cache' ); $iterations = $this->getOption( 'i', 100 ); if ( $cache ) { if ( !isset( $wgObjectCaches[$cache] ) ) { $this->error( "MediaWiki isn't configured with a cache named '$cache'", 1 ); } $servers = $wgObjectCaches[$cache]['servers']; } elseif ( $this->hasArg() ) { $servers = array( $this->getArg() ); } elseif ( $wgMainCacheType === CACHE_MEMCACHED ) { global $wgMemCachedServers; $servers = $wgMemCachedServers; } elseif ( isset( $wgObjectCaches[$wgMainCacheType]['servers'] ) ) { $servers = $wgObjectCaches[$wgMainCacheType]['servers']; } else { $this->error( "MediaWiki isn't configured for Memcached usage", 1 ); } # find out the longest server string to nicely align output later on $maxSrvLen = $servers ? max( array_map( 'strlen', $servers ) ) : 0; foreach ( $servers as $server ) { $this->output( str_pad( $server, $maxSrvLen ), $server # output channel ); $mcc = new MemCachedClientforWiki( array( 'persistant' => true, 'timeout' => $wgMemCachedTimeout ) ); $mcc->set_servers( array( $server ) ); $set = 0; $incr = 0; $get = 0; $time_start = $this->microtime_float(); for ( $i = 1; $i <= $iterations; $i++ ) { if ( $mcc->set( "test$i", $i ) ) { $set++; } } for ( $i = 1; $i <= $iterations; $i++ ) { if ( !is_null( $mcc->incr( "test$i", $i ) ) ) { $incr++; } } for ( $i = 1; $i <= $iterations; $i++ ) { $value = $mcc->get( "test$i" ); if ( $value == $i * 2 ) { $get++; } } $exectime = $this->microtime_float() - $time_start; $this->output( " set: $set incr: $incr get: $get time: $exectime", $server ); } }
public function execute() { global $wgMemCachedServers; $iterations = $this->getOption('i', 100); if ($this->hasArg()) { $wgMemCachedServers = array($this->getArg()); } foreach ($wgMemCachedServers as $server) { $this->output($server . " "); $mcc = new MemCachedClientforWiki(array('persistant' => true)); $mcc->set_servers(array($server)); $set = 0; $incr = 0; $get = 0; $time_start = $this->microtime_float(); for ($i = 1; $i <= $iterations; $i++) { if (!is_null($mcc->set("test{$i}", $i))) { $set++; } } for ($i = 1; $i <= $iterations; $i++) { if (!is_null($mcc->incr("test{$i}", $i))) { $incr++; } } for ($i = 1; $i <= $iterations; $i++) { $value = $mcc->get("test{$i}"); if ($value == $i * 2) { $get++; } } $exectime = $this->microtime_float() - $time_start; $this->output("set: {$set} incr: {$incr} get: {$get} time: {$exectime}\n"); } }
/** * Constructor. * * Available parameters are: * - servers: The list of IP:port combinations holding the memcached servers. * - debug: Whether to set the debug flag in the underlying client. * - persistent: Whether to use a persistent connection * - compress_threshold: The minimum size an object must be before it is compressed * - timeout: The read timeout in microseconds * - connect_timeout: The connect timeout in seconds * * @param $params array */ function __construct($params) { if (!isset($params['servers'])) { $params['servers'] = $GLOBALS['wgMemCachedServers']; } if (!isset($params['debug'])) { $params['debug'] = $GLOBALS['wgMemCachedDebug']; } if (!isset($params['persistent'])) { $params['persistent'] = $GLOBALS['wgMemCachedPersistent']; } if (!isset($params['compress_threshold'])) { $params['compress_threshold'] = 1500; } if (!isset($params['timeout'])) { $params['timeout'] = $GLOBALS['wgMemCachedTimeout']; } if (!isset($params['connect_timeout'])) { $params['connect_timeout'] = 0.1; } $this->client = new MemCachedClientforWiki($params); $this->client->set_servers($params['servers']); $this->client->set_debug($params['debug']); }
public function execute() { global $wgMainCacheType, $wgMemCachedTimeout, $wgObjectCaches; $cache = $this->getOption('cache'); $iterations = $this->getOption('i', 100); if ($cache) { if (!isset($wgObjectCaches[$cache])) { $this->error("MediaWiki isn't configured with a cache named '{$cache}'", 1); } $servers = $wgObjectCaches[$cache]['servers']; } elseif ($this->hasArg()) { $servers = array($this->getArg()); } elseif ($wgMainCacheType === CACHE_MEMCACHED) { global $wgMemCachedServers; $servers = $wgMemCachedServers; } elseif (isset($wgObjectCaches[$wgMainCacheType]['servers'])) { $servers = $wgObjectCaches[$wgMainCacheType]['servers']; } else { $this->error("MediaWiki isn't configured for Memcached usage", 1); } foreach ($servers as $server) { $this->output($server . " ", $server); $mcc = new MemCachedClientforWiki(array('persistant' => true, 'timeout' => $wgMemCachedTimeout)); $mcc->set_servers(array($server)); $set = 0; $incr = 0; $get = 0; $time_start = $this->microtime_float(); for ($i = 1; $i <= $iterations; $i++) { if (!is_null($mcc->set("test{$i}", $i))) { $set++; } } for ($i = 1; $i <= $iterations; $i++) { if (!is_null($mcc->incr("test{$i}", $i))) { $incr++; } } for ($i = 1; $i <= $iterations; $i++) { $value = $mcc->get("test{$i}"); if ($value == $i * 2) { $get++; } } $exectime = $this->microtime_float() - $time_start; $this->output("set: {$set} incr: {$incr} get: {$get} time: {$exectime}", $server); } }
{ list($usec, $sec) = explode(" ", microtime()); return (double) $usec + (double) $sec; } if (isset($argv[0])) { $wgMemCachedServers = array($argv[0]); } // 100 is default; can be specified through 2nd param $iterations = isset($argv[1]) ? $argv[1] : 100; if (count($wgMemCachedServers) <= 0) { die("No servers to test!\n"); } foreach ($wgMemCachedServers as $server) { print "{$server} "; $mcc = new MemCachedClientforWiki(array('persistant' => true)); $mcc->set_servers(array($server)); $set = 0; $incr = 0; $get = 0; $key = wfMemcKey(wfHostname() . "-test"); $time_start = microtime_float(); for ($i = 1; $i <= $iterations; $i++) { if (!is_null($mcc->set("{$key}{$i}", $i))) { $set++; } } for ($i = 1; $i <= $iterations; $i++) { if (!is_null($mcc->incr("{$key}{$i}", $i))) { $incr++; } }
function &getMemc() { global $wgSessionMemCachedServers, $wgMemc, $wgSessionMemc; global $wgMemCachedPersistent, $wgMemCachedDebug; if (!empty($wgSessionMemCachedServers) && is_array($wgSessionMemCachedServers) && class_exists('MemcachedClientforWiki')) { if (!empty($wgSessionMemc) && is_object($wgSessionMemc) && $wgSessionMemc instanceof MemCachedClientforWiki) { return $wgSessionMemc; } else { $wgSessionMemc = new MemCachedClientforWiki(array('persistant' => $wgMemCachedPersistent, 'compress_threshold' => 1500)); $wgSessionMemc->set_servers($wgSessionMemCachedServers); $wgSessionMemc->set_debug($wgMemCachedDebug); return $wgSessionMemc; } } else { return $wgMemc; } }