Redis Pipeline Technology
Redis is based on a client - server model and a request / response protocol TCP services. This means that a request will typically follow these steps:
- The client sends a query to the server, and listens Socket returns, usually in blocking mode, waiting for the server response.
- Server processing commands and returns the results to the client.
Redis Pipeline Technology
Redis pipeline technology can not respond at the time of the server, the client can continue to send a request to the server, and eventually all at once to read the response of the server.
Examples
See redis pipeline, just you need to start redis instance and enter the following command:
$(echo -en "PING\r\n SET w3bigkey redis\r\nGET w3bigkey\r\nINCR visitor\r\nINCR visitor\r\nINCR visitor\r\n"; sleep 10) | nc localhost 6379 +PONG +OK redis :1 :2 :3
By using the above example wePING command redis service is available, then we have set up w3bigkey value redis, and then we get the value w3bigkey and make visitor increment 3 times.
In the returned results, we can see these commands at once submitted to redis service, and ultimately all at once to read the response of the server
Advantage Pipeline Technology
The most significant advantage of technology to improve pipeline performance redis service.
Some test data
In the following test, we will use the Redis Ruby client that supports pipeline technical characteristics, the test pipe technology to enhance the effect of speed.
require 'rubygems' require 'redis' def bench(descr) start = Time.now yield puts "#{descr} #{Time.now-start} seconds" end def without_pipelining r = Redis.new 10000.times { r.ping } end def with_pipelining r = Redis.new r.pipelined { 10000.times { r.ping } } end bench("without pipelining") { without_pipelining } bench("with pipelining") { with_pipelining }
From the LAN in Mac OS X system to perform the above data indicate that this simple script, open the pipeline operation, the round-trip delay has been improved quite low.
without pipelining 1.185238 seconds with pipelining 0.250783 seconds
As you can see, open the pipeline, we speed efficiency by 5 times.