コード例 #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
 /**
  * @param $key string
  * @param $value int
  * @return Mixed
  */
 public function incr($key, $value = 1)
 {
     return $this->client->incr($this->encodeKey($key), $value);
 }
コード例 #5
0
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++;
        }
    }
    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) {
コード例 #6
0
ファイル: mctest.php プロジェクト: BackupTheBerlios/blahtex
}
foreach ($wgMemCachedServers as $server) {
    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());