Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php memcached需要这么长时间吗?_Php_Memcached - Fatal编程技术网

Php memcached需要这么长时间吗?

Php memcached需要这么长时间吗?,php,memcached,Php,Memcached,我比较了这两段代码: 测试1: $time = microtime(true); $memcached = new Memcached(); $memcached->addServer('localhost', 11211); for($i=1;$i<=1000;$i++){ $result = $memcached->get('test'); } echo (microtime(true) - $time)*1000; $time = microtime(tru

我比较了这两段代码:

测试1:

$time = microtime(true);

$memcached = new Memcached();
$memcached->addServer('localhost', 11211);

for($i=1;$i<=1000;$i++){
   $result = $memcached->get('test');
}

echo (microtime(true) - $time)*1000;
$time = microtime(true);

$memcached = new Memcached();
$memcached->addServer('localhost', 11211);

for($i=1;$i<=1000;$i++){
   $result = 'just me';
}

echo (microtime(true) - $time)*1000;
$time=microtime(真);
$memcached=newmemcached();
$memcached->addServer('localhost',11211);
对于($i=1;$iget('test');
}
回波(微时间(真)-$time)*1000;
结果时间:50.509929656982


测试2:

$time = microtime(true);

$memcached = new Memcached();
$memcached->addServer('localhost', 11211);

for($i=1;$i<=1000;$i++){
   $result = $memcached->get('test');
}

echo (microtime(true) - $time)*1000;
$time = microtime(true);

$memcached = new Memcached();
$memcached->addServer('localhost', 11211);

for($i=1;$i<=1000;$i++){
   $result = 'just me';
}

echo (microtime(true) - $time)*1000;
$time=microtime(真);
$memcached=newmemcached();
$memcached->addServer('localhost',11211);

对于($i=1;$i在典型的memcached设置中,我希望几乎每项操作都能在1ms或更短的时间内完成。我建议检查您的网络延迟,然后对客户端进行分析,以查看客户端实际处理操作所花费的时间。如果您可以排除那些速度较慢的操作,那么您可能需要某种类型的服务器附带问题。

你在那里做了很多令人困惑的数学题。我认为你的问题一点也不清楚

看起来原始答案乘以1000后得到了50.509929656982ms。所以我要将其乘以~50510µs的原始答案。现在,这是针对1000个请求的,所以平均请求在~50µs内返回

现在,如果你真的想要抓取1000个项目,你可以在一个multiget请求中完成,这将大大减少平均每个项目的时间

如果你问形成和传输网络请求并获得网络响应、解析它并返回它的时间是否比紧循环中的NOOP分配慢,那么,是的


如果你问50µs是快还是慢…这真的取决于你。

你能尝试
$memcached->connect()
而不是
$memcached->addServer()
?这将确保在你真正开始
获取
之前建立连接。