美文网首页
Redis管道机制

Redis管道机制

作者: lintong | 来源:发表于2015-03-10 20:19 被阅读119次

Redis is a TCP server using the client-server model and what is called
a Request/Response protocol.
This means that usually a request is accomplished with the following steps:

  • The client sends a query to the server, and reads from the socket, usually in a blocking way, for the server response.
  • The server processes the command and sends the response back to the client.
    So for instance a four commands sequence is something like this:
Client: INCR X
Server: 1
Client: INCR X
Server: 2
Client: INCR X
Server: 3
Client: INCR X
Server: 4

Clients and Servers are connected via a networking link. Such a link can be very fast (a loopback interface) or very slow (a connection established over the Internet with many hops between the two hosts). Whatever the network latency is, there is a time for the packets to travel from the client to the server, and back from the server to the client to carry the reply.
This time is called RTT (Round Trip Time). It is very easy to see how this can affect the performances when a client needs to perform many requests in a row (for instance adding many elements to the same list, or populating a database with many keys). For instance if the RTT time is 250 milliseconds (in the case of a very slow link over the Internet), even if the server is able to process 100k requests per second, we'll be able to process at max four requests per second.
If the interface used is a loopback interface, the RTT is much shorter (for instance my host reports 0,044 milliseconds pinging 127.0.0.1), but it is still a lot if you need to perform many writes in a row.
Fortunately there is a way to improve this use case.

Redis Pipelining

A Request/Response server can be implemented so that it is able to process new requests even if** the client didn't already read the old responses**. This way it is possible to send multiple commands to the server without waiting for the replies at all, and finally read the replies in a single step.

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 this 10k commands.

相关文章

  • Redis管道机制

    Redis is a TCP server using the client-server model and w...

  • Redis管道技术的使用

    目录 Redis 管道技术 SpringDataRedis 使用管道 Redis 管道的性能测试 使用管道技术的注...

  • 高级篇之一

    Redis高级功能之分管道技术、消息队列 一、管道技术 我们先来试试管道技术,Redis 管道技术可以在服务端未响...

  • 管道机制

    本文摘抄自linux基础编程 管道指的是从一个进程连接数据流到另一个进程。它具有以下特点: 管道是半双工的,数据只...

  • Redis管道

    客户端和Redis使用TCP协议连接。不论是客户端向redis发送命令还是redis向客户端返回命令的执行...

  • redis管道

    redis单个请求与批量操作对比   Redis是一种基于客户端-服务端模型以及请求/响应协议的TCP服务。这意味...

  • Redis管道

    Redis之管道的使用原文地址: https://blog.piaoruiqing.com/blog/2019/...

  • 简单梳理一下Redis实现分布式Session,建议做java开

    Redis实现分布式Session管理 Memcached管理机制 Redis管理机制 redis的session...

  • Spring MVC 知识点疏理

    1. Redis 存储方式 Redis存储机制分成两种Snapshot 和 AOF。无论是那种机制,Redis都是...

  • Redis-管道

    Redis管道的使用原文介绍:http://redis.cn/topics/pipelining.html[htt...

网友评论

      本文标题:Redis管道机制

      本文链接:https://www.haomeiwen.com/subject/koavxttx.html