为什么在AWS实例上从Redis获取数据非常慢


Why data fetching from Redis is very slow on AWS Instance

首先,我使用以下链接在本地机器(Ubuntu 14.04)上安装了redis。

https://www.digitalocean.com/community/tutorials/how-to-install-and-use-redishttps://www.digitalocean.com/community/tutorials/how-to-set-up-a-redis-server-as-a-session-handler-for-php-on-ubuntu-14-04

我正在使用哈希将数据存储在redis中。当数据库命中时,查询花费了大约300毫秒,从redis获取时花费了60-70毫秒。在那之后,我在我的ubuntu AMI上做了同样的事情,它是m4大的,但不幸的是,我没有看到响应时间有任何变化,有时它需要比数据库命中更多的时间。我不知道我在哪里失踪了。

    $this->redis = New 'Redis();
    $this->redis->connect('127.0.0.1', 6379);
    $this->redis-hset($id, $key, serialize($result));
    if($this->redis->hexists($id,$key)) {
         return $this->redis->hget($id, $key);
    }

我确信,当它在redis中可用时,它会从redis中获取数据。

我建议尝试另一种实例类型。m4.large只是一个2核的实例类型,也许可以尝试4核?或者使用AWS弹性缓存redis服务。

在这里也可以找到一些有用的信息。

基准序列化时间-对于更复杂的数据序列化/非序列化,比实际写入redis要长得多。(检查http://kiss-web.blogspot.com/2016/02/memcached-vs-redisphpredis-vs-predis-vs.html)