当前位置:网站首页>Redis pipeline technology speed and efficiency increased by 5 times

Redis pipeline technology speed and efficiency increased by 5 times

2022-06-24 04:54:00 User 1685462

Redis It's a client based - Server model and request / In response to the protocol TCP service . This means that normally a request follows these steps :

  • The client sends a query request to the server , And monitor Socket return , Usually in blocking mode , Waiting for the server to respond .
  • The server handles commands , And return the result to the client .

Redis Pipeline technology

Redis Pipeline technology can be used when the server is not responding , The client can continue to send requests to the server , And finally read all the server's responses at once .

example

see redis The Conduit , Just start redis Instance and enter the following command :

$(echo -en "PING\r\n SET runoobkey redis\r\nGET runoobkey\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 PING Command view redis Is the service available , And then we set up runoobkey The value of is redis, Then we get runoobkey And make visitor Self increasing 3 Time .

In the returned results, we can see that these commands are directed to redis Service submission , And finally read all the server's responses at once


Advantages of Pipeline Technology

The most significant advantage of pipeline technology is the improvement of redis Service performance .

Some test data

In the following test , We will use Redis Of Ruby client , Support pipeline technical characteristics , Test the effect of pipeline technology on 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... In the LAN Mac OS X The data of executing the above simple script on the system shows that , After opening the pipeline operation , Round trip delay has been improved to a fairly low level .

without pipelining 1.185238 seconds 
with pipelining 0.250783 seconds

As you can see , After opening the pipe , Our speed and efficiency have improved 5 times .

原网站

版权声明
本文为[User 1685462]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/09/20210901101518358k.html