The Redis itself is a CS-mode TCP server, and the client can initiate multiple request commands sequentially through a socket. After each request command is issued, the client usually blocks and waits for the Redis server to process the Redis service end to return the result to the client.
Redis's Pipeline (piping) functionality is not available on the command line, but Redis supports pipeline and is implemented in every language version of the client. Due to network overhead delay, the Redis server side has a strong processing capacity, but also due to the low number of client messages received, resulting in a small throughput. When a client uses pipelining to send a command, the Redis server must place a partial request into the queue (using memory) to send the results at once, and if a lot of names are sent, it is recommended to label the returned results, which, of course, will increase the memory used;
Pipeline is useful in some scenarios, such as having multiple command submissions that need to be "in time", and they are not dependent on the results, and the response to the results is not immediately available, so pipeline can act as a "batch" tool, and to a certain extent, Can improve performance significantly, the main reason for performance improvement is that the TCP link less "interactive round-trip" time. However, when encoding, note that the "exclusive" link during pipeline will not be possible for other operations other than "pipe" types until pipeline is closed, and if your pipeline instruction set is large, in order not to interfere with other actions in the link, You can create a new client link for the pipeline operation, leaving the pipeline and other normal operations separated into 2 client. However, the number of pipeline in fact tolerable, and the size of the socket-output buffer size/return result is significant, and also means that the number of pipeline links that each redis-server can support at the same time is limited, This will be limited by the ability of the server's physical memory or network interface to buffer.
Python Test code:
Submit 10,000 command at the same time:
#!/usr/bin/python2
Import redis
import time
def without_pipeline ():
R=redis. Redis () for
I in range (10000):
r.ping ()
return
def with_pipeline ():
R=redis. Redis ()
pipeline=r.pipeline () for
I in range (10000):
pipeline.ping ()
Pipeline.execute (
) return
def bench (DESC):
start=time.clock () desc () Stop=time.clock
(
) Diff=stop-start
print '%s has token%s '% (Desc.func_name,str (diff))
if __name__== ' __main__ ':
Bench (Without_pipeline)
Bench (With_pipeline)
Test results:
[Root@localhost ~]# Python2 redis_piple.py
Without_pipeline has token 1.11
With_pipeline has token 0.29
Note: In native testing, network latency is largely ignored, and pipeline still has high performance.
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/database/storage/