Redis - pipelining

Using pipelining to speedup Redis queries

Request/Response protocols and RTT

Redis is a TCP server,using the client-server model and what is called a Request/Response protocol。

通常一个请求以以下步骤完成:

  • client向server发送一个请求,并从socket读取server的response,通常以阻塞方式。
  • server 处理这个命令并发送响应返回给client。

 

Redis Pipelining

IMPORTANT NOTE: While the client sends commands using pipelining, the server will be forced to queue the replies, using memory. So if you need to send a lot of commands with pipelining, it is better to send them as batches having a reasonable number, for instance 10k commands, read the replies, and then send another 10k commands again, and so forth. The speed will be nearly the same, but the additional memory used will be at max the amount needed to queue the replies for these 10k commands.

 

It's not just a matter of RTT

管道不仅仅减少RTT的延迟开销,实际上提升了redis服务器每秒可以执行的总操作数量。如果不使用管道,服务每个命令从访问数据结构和生成回复的角度是非常便宜的,但从做socket I/O的角度来说是非常昂贵的。这涉及到调用 read() 和 write() 系统调用,意味着从 user land到kernel land。

posted @ 2021-03-01 15:08  听雨1  阅读(25)  评论(0)    收藏  举报