Пример #1
0
 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
	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 );
		}
	}
Пример #3
0
 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);
     }
 }
 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;
 }
Пример #5
0
 /**
  * @param $key string
  * @param $value
  * @param $exptime int If it's equal to zero, the item will never expire!
  * @return bool
  */
 public function set($key, $value, $exptime = 0)
 {
     return $this->client->set($this->encodeKey($key), $value, $exptime);
 }
Пример #6
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++;
        }
    }
    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)));
Пример #7
0
}
if (isset($options['i'])) {
    $iterations = $options['i'];
} else {
    $iterations = 100;
}
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;