Redis Pipeline
A quick introduction & Pro-tip technique to speed up your Redis commands execution
Preamble
Redis Pipeline is technique for improving performance by wrapping up bunch of Redis commands into a single process, without waiting for the response to each individual command.
Round-Trip Time (RTT)
Redis client-server using TCP connection to established, where the client send redis command (Request) to the server and client waiting for server (Response), that’s how Redis command executed without Pipeline, it’s still ok if you only execute one command, when you execute multiple command it’s gonna be faster if you use pipeline.
No Pipeline
Client ask to open connection to server, and execute one redis commands through one TCP request, and client do the same but with different redis command, until 3 times and connection closed.
Pipeline
Client ask to open connection to server, and execute several redis commands through one TCP request, and server executing all commands that client sent, without response each command status to client, after server done, it will send response to client that pipeline already execute those commands.
Conclusion
If you need to perform multiple commands with faster, you can use redis pipeline, otherwise if you just perform one command inside a function you can use non pipeline redis.
Benchmark Result
This benchmark data generated by golang benchmark, I use golang as the redis client for prove which one is faster by comparing bulk insert 1024 data, using Non Pipeline & Pipeline.
Non Pipeline
Non Pipeline take more and more time, through data quantity from 1 to 1024, it’s going slower because Non pipeline execute insert command and waiting the response, and executed inside different TCP Request, it’s mean if the data quantity increase it goes slow, because the client perform 1024 TCP Request to server.
Pipeline
Pipeline time execution is almost linear, with pipeline the client perform multiple command that sent through one TCP Request, and server execute all the commands and response to client when all commands already execute, pipeline process 1024 command more faster.
That’s it, thankyou for coming up.