コード例 #1
0
ファイル: mctest.php プロジェクト: rocLv/conference
 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");
     }
 }
コード例 #2
0
ファイル: mctest.php プロジェクト: MediaWiki-stable/1.26.1
 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);
         $mcc = new MemCachedClientforWiki(array('persistant' => true, 'timeout' => $wgMemCachedTimeout));
         $mcc->set_servers(array($server));
         $set = 0;
         $incr = 0;
         $get = 0;
         $time_start = microtime(true);
         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 = microtime(true) - $time_start;
         $this->output(" set: {$set}   incr: {$incr}   get: {$get} time: {$exectime}", $server);
     }
 }
コード例 #3
0
ファイル: mctest.php プロジェクト: mangowi/mediawiki
 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);
     }
 }
コード例 #4
0
 public function get($key)
 {
     if (mt_rand(1, 100) < 20) {
         $shadow = Wikia\Measurements\Time::run(get_class($this->shadow) . '/' . __FUNCTION__, function () use($key) {
             return $this->shadow->get($key);
         });
         $result = Wikia\Measurements\Time::run('MemCachedClientforWiki/' . __FUNCTION__, function () use($key) {
             return parent::get($key);
         });
     } else {
         $shadow = $this->shadow->get($key);
         $result = parent::get($key);
     }
     if ($shadow != $result) {
         $this->get_sock($key, $host);
         $this->shadow->get_sock($key, $shadowHost);
         Wikia::log(__METHOD__, false, "{$key} {$host}/{$shadowHost}", true);
     }
     return $result;
 }
コード例 #5
0
 /**
  * @param $key string
  * @return Mixed
  */
 public function get($key)
 {
     return $this->client->get($this->encodeKey($key));
 }
コード例 #6
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++;
     }
 }
 for ($i = 1; $i <= $iterations; $i++) {
     $value = $mcc->get("{$key}{$i}");
     if ($value == $i * 2) {
         $get++;
     }
 }
 $exectime = sprintf("%dms", round(1000 * (microtime_float() - $time_start)));
 $err = '';
 if ($set != $iterations) {
     $err .= 'error: ' . $set . ' SET ops completed ';
 }
 if ($incr != $iterations) {
     $err .= 'error: ' . $incr . ' INCR ops completed ';
 }
 if ($get != $iterations) {
     $err .= 'error: ' . $get . ' GET ops completed ';
 }
コード例 #7
0
ファイル: mctest.php プロジェクト: BackupTheBerlios/blahtex
    print "{$server} ";
    $mcc = new MemCachedClientforWiki(array('persistant' => true));
    $mcc->set_servers(array($server));
    $set = 0;
    $incr = 0;
    $get = 0;
    $time_start = 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 = microtime_float() - $time_start;
    print "set: {$set}   incr: {$incr}   get: {$get} time: {$exectime}\n";
}
function microtime_float()
{
    list($usec, $sec) = explode(" ", microtime());
    return (double) $usec + (double) $sec;
}