May 16, 2021 Redis
Redis is a TCP service based on a client-service-side model and a request/response protocol. This means that typically a request follows the following steps:
Redis pipeline technology allows clients to continue sending requests to the service side and eventually read all service-side responses at once when the service side is not responding.
To view the redis pipeline, you only need to launch the redis instance and enter the following command:
$(echo -en "PING\r\n SET w3ckey redis\r\nGET w3ckey\r\nINCR visitor\r\nINCR visitor\r\nINCR visitor\r\n"; sleep 10) | nc localhost 6379 +PONG +OK redis :1 :2 :3
In the above example we use the PING command to see if the redis service is available, and then we set the value of w3ckey to redis, and then we get the value of w3ckey and increase the visitor three times.
In the results returned, we can see that these commands are committed to the redis service at once and eventually read all service-side responses at once
The most significant advantage of pipeline technology is the improved performance of the redis service.
In the following tests, we will use Redis' Ruby client to support pipeline technology features and test the speed improvement of pipeline technology.
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 }
Data from this simple script above from a Mac OS X system on a local area network shows that the round-trip delay has improved considerably since the pipeline operation was opened.
without pipelining 1.185238 seconds with pipelining 0.250783 seconds
As you can see, when we open the pipe, we're five times faster.