简体   繁体   English

Cloud Redis延迟原因(与Macbook Pro上的本地Redis)

[英]Cloud Redis latency causes (vs. local redis on macbook pro)

Redis can give sub millisecond response times. Redis可以给出不到毫秒的响应时间。 That's a great promise. 这是一个很大的希望。 I'm testing heroku redis and I get 1ms up to about 8ms , for a zincrby . 我正在测试heroku redis,对于zincrby ,我得到1ms到大约8mszincrby I'm using microtime() in php to wrap the call. 我在php中使用microtime()来包装调用。 This heroku redis (I'm using the free plan) is a shared instance and there is resource contention so I expect response times for identical queries to vary, and they certainly do. 这个heroku redis(我正在使用免费计划)是一个共享实例,并且存在资源争用,因此我希望相同查询的响应时间会有所不同,而且肯定会。

I'm curious as to the cause of the difference in performance vs. redis installed on my macbook pro via homebrew. 我很好奇通过自制软件在Macbook Pro上安装的性能与Redis的性能差异的原因。 There's obviously no network latency there. 那里显然没有网络延迟。 What I'm curious about is does this mean that any cloud redis (ie connecting over the network, say within aws), is always going to be quite a bit slower than if I were to have one cloud server and run a redis inside the same physical machine, thus eliminating network latency? 我很好奇的是,这是否意味着与我拥有一台云服务器并在内部运行redis相比,任何云redis(即通过网络连接,例如在AWS中)总是会慢很多。同一台物理计算机,从而消除了网络延迟?

There is also resource contention in these cloud offerings, unless a private server is chosen which costs a lot more. 这些云产品中也存在资源争用,除非选择了价格昂贵的私有服务器。

Some numbers: my local macbook pro consistently gives 0.2ms for the identical zincrby that takes between 1ms & 8ms on the heroku redis. 一些数字:我的本地macbook pro始终为相同的zincrby提供0.2ms的时间,在heroku redis上花费1ms8ms时间。

Is network latency the cause of this? 网络延迟是造成这种情况的原因吗?

No, probably not. 不,可能不会。

The typical latency of a 1 Gbit/s network is about 200us . 1 Gbit / s网络的典型延迟约为200us That's 0.2ms . 那是0.2ms

What's more, in aws you're probably on 10gbps at least. 而且,在aws中,您的速度可能至少为10gbps。

As this page in the redis manual explains, the main cause of the latency variation between these two environments will almost certainly be a result of the higher intrinsic latency (there's a redis command to test this on any particular system: redis-cli --intrinsic-latency 100 , see the manual page above) arising from being run in a linux container . 正如redis手册中的该页面所解释的那样,这两种环境之间的延迟变化的主要原因几乎肯定是intrinsic latency较高的结果(有redis命令可以在任何特定系统上对此进行测试: redis-cli --intrinsic-latency 100 ,请参见上面的手册页)是由于在linux容器中运行而引起的

ie, network latency is not the dominant cause of the variation seen here. 也就是说,网络延迟不是此处变化的主要原因。

Here is a checklist (from redis manual page linked above). 这是一个清单(来自上面链接的redis手册页)。

  • If you can afford it, prefer a physical machine over a VM to host the server. 如果负担得起,则最好使用物理机而不是VM来承载服务器。
  • Do not systematically connect/disconnect to the server (especially true for web based applications). 不要系统地连接/断开与服务器的连接(对于基于Web的应用程序尤其如此)。 Keep your connections as long lived as possible. 保持连接尽可能长久。
  • If your client is on the same host than the server, use Unix domain sockets. 如果客户端与服务器位于同一主机上,请使用Unix域套接字。
  • Prefer to use aggregated commands (MSET/MGET), or commands with variadic parameters (if possible) over pipelining. 最好在管道上使用聚合命令(MSET / MGET)或带有可变参数的命令(如果可能)。
  • Prefer to use pipelining (if possible) over sequence of roundtrips. 优先在往返序列上使用流水线(如果可能)。
  • Redis supports Lua server-side scripting to cover cases that are not suitable for raw pipelining (for instance when the result of a command is an input for the following commands). Redis支持Lua服务器端脚本来覆盖不适合原始流水线的情况(例如,当命令的结果是以下命令的输入时)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM