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"); } }
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 $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); } }
function _safe_fwrite($f, $host, $buf, $len = false) { $buf = self::PROTOCOL . ":{$host} {$buf}"; if ($len !== false) { $len = strlen($buf); } return parent::_safe_fwrite($f, $host, $buf, $len); }
/** * Do a get_multi request and optionally return the data if required * * @author Władysław Bodzek <*****@*****.**> * @param $keys array List of keys * @parma $returnData bool Return the data? * @return array */ protected function getMultiInternal($keys, $returnData) { $map = array(); foreach ($keys as $key) { $map[$this->encodeKey($key)] = $key; } $mappedData = $this->client->get_multi(array_keys($map)); if (!$returnData) { return true; } $data = array(); foreach ($mappedData as $k => $v) { $data[$map[$k]] = $v; } return $data; }
public function set($key, $value, $exp = 0) { if (mt_rand(1, 100) < 20 && $exp != 0) { $shadowKey = $key . ":moxi_shadow"; Wikia\Measurements\Time::run(get_class($this->shadow) . '/' . __FUNCTION__, function () use($shadowKey, $value, $exp) { return $this->shadow->set($shadowKey, $value, $exp); }); $result = Wikia\Measurements\Time::run('MemCachedClientforWiki/' . __FUNCTION__, function () use($key, $value, $exp) { return parent::set($key, $value, $exp); }); } else { $result = parent::set($key, $value, $exp); } if ($result) { $this->shadow->_dupe_cache[$key] = $value; } return $result; }
/** * @param $key string * @param $value int * @return Mixed */ public function decr($key, $value = 1) { return $this->client->decr($this->encodeKey($key), $value); }
function microtime_float() { 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; } }