Fastest Redis Client Library for Go

Rizal Widyarta Gowandy
Level Up Coding
Published in
2 min readApr 25, 2021

--

Benchmarking some popular Redis client libraries for Go to find the fastest one.

Motivation

Increasing RPS (request per second) is not an easy task. Changing your code to increase performance is even more challenging. There are several popular libraries out there, and almost every single one claims to be the fastest. The problem arises when the benchmarking result is out of date. Even worse when the one who did the benchmark tunes the library in a non-general way. Hence, the achieve the same performance is pretty much impossible for the general user.

The purpose of the benchmark is to find the fastest Redis client library for Go with a controlled environment and without any magic hack to tune any of the libraries.

Environment

Go client libraries used:

Max connection pool size 100 and 1000.

Cluster mode on and off with replica size of 5. Except for gomodule/redigo which currently do not support a cluster client mode.

Benchmarking Result

The result below is the average result after running the benchmark 25 times.

Understanding the Result

There are four columns on the right side of each Redis operation like GET included in the result above. The meaning for each one of them is:

  • iteration => the number of iterations of the operation run, a higher value is better.
  • ns/op => this is the average time each function call takes to complete, a smaller value is better.
  • B/op => this is the average memory used for each function call, a smaller value is better.
  • allocs/o => this is the average memory allocation for each function call, a smaller value is better.

We can see go-redis/redis/v8/cluster-pool:1000 outperformed other libraries almost across all the operation benchmarks. Excluding the EXPIRE operation where mediocregopher/radix/v3/cluster-pool:1000 actually outperformed it by a small margin.

Another interesting result such as that gomodule/redigo-pool:100 actually outperformed gomodule/redigo-pool:1000 on a certain operation like HGET. This is most likely because the increase of the connection pool increases the competition for resource allocation in a limited resource environment. Having a small connection pool allows the previous operation to be done first before handling the next one. Since there is no resource allocation competition it actually can perform better than one with a higher connection pool. It means we shouldn’t blindly increase the max connection pool and believe that the operation will go faster.

Conclusion

By looking at the result above, we can conclude that go-redis/redis/v8 with cluster mode on is the overall fastest Redis client library for Go. It’s recommended to use it with cluster mode on, and with dedicated max connection pool size based on your own environment. Some testing is required to find the balance max connection pool size depending on your most heavy operations.

--

--

Software Engineer | INTJ | Choleric | The Questioner (CD) | Creator & Advisor