Redis Performance Benchmarking

Redis Performance Benchmarking is very important when you setup Redis in your environment. With the help of benchmarking you will be able to know how fast Redis reads and writes will be.

Ok, So we know that Redis is Fast, But tell me how fast Redis is, How can I measure the speed on my server?

Redis provides an utility called "redis-benchmark" to measure the performance on a system or environment. It is a good practice that you run this utility in your environment to understand the performance you will be able to achieve in your production environment. This utility is also inside “src” folder, this is the same place where redis-server utility exists.

 

Before we proceed further, it is worth mentioning that in this article I am running a demo server which is extremely low in configuration. So don’t judge Redis by the output you see here. Run redis-benchmark utility in production like server and see the great output.

Here is what my server configuration looks like:

$ lscpu

Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 2
On-line CPU(s) list: 0,1
Thread(s) per core: 2

 

Alright, Let’s Begin!!!

Here is a sample redis-benchmark utility command looks like:

redis-benchmark -q -n 1000000
Understanding the command:

-q means run this in a quit mode and just display us the output in terms of number of requests handled per second.
-n means the total number of queries to run during this test. So in above command, Redis will perform 1 Million Transactions.

By default Redis tests all the operations as shown below in a sample test:

$ redis-benchmark -h 10.128.0.2 -q -n 100

PING_INLINE: 20000.00 requests per second
PING_BULK: 25000.00 requests per second
SET: 20000.00 requests per second
GET: 25000.00 requests per second
INCR: 25000.00 requests per second
LPUSH: 16666.67 requests per second
RPUSH: 14285.71 requests per second
LPOP: 25000.00 requests per second
RPOP: 25000.00 requests per second
SADD: 14285.71 requests per second
HSET: 25000.00 requests per second
SPOP: 25000.00 requests per second
LPUSH (needed to benchmark LRANGE): 20000.00 requests per second
LRANGE_100 (first 100 elements): 20000.00 requests per second
LRANGE_300 (first 300 elements): 20000.00 requests per second
LRANGE_500 (first 450 elements): 20000.00 requests per second
LRANGE_600 (first 600 elements): 25000.00 requests per second
MSET (10 keys): 20000.00 requests per second

However if you are interested in running test only on some specific operation such as GET or SET, then you can do so by using -t parameter as shown below:

$ redis-benchmark -h 10.128.0.2 -q -n 100 -t get

GET: 9090.91 requests per second

If you want to test multiple commands, then provide all the list of commands separated by a comma to -t parameter as shown below:

$ redis-benchmark -h 10.128.0.2 -q -n 100 -t get,set,lpush

SET: 33333.33 requests per second
GET: 25000.00 requests per second
LPUSH: 25000.00 requests per second

By Default Redis runs all these benchmarks against a single key. However If you want to test more real world scenario with random dynamic keys then you can use -r parameter.

$ redis-benchmark -h 10.128.0.2 -q -n 100 -t get,set,lpush -r 100
SET: 16666.67 requests per second
GET: 14285.71 requests per second
LPUSH: 11111.11 requests per second

By default, key-value data size is considered to be 2 bytes when you run redis-benchmark utility. However, If you know that the data size of your read or write is going to be bigger then you can test that by using -d parameter as shown in below example. Here we’re saying that the size of our key-value pair will be 500 Bytes:

$ redis-benchmark -h 10.128.0.2 -q -n 100 -t get,set,lpush -r 100 -d 500
SET: 14285.71 requests per second
GET: 20000.00 requests per second
LPUSH: 20000.00 requests per second

Alright, So since you are familiar by now on running redis-benchmark utility, here is the full command and available parameters which you can use during your tests:

Usage: redis-benchmark [-h <host>] [-p <port>] [-c <clients>] [-n <requests]> [-k <boolean>]

 -h <hostname>      Server hostname (default 127.0.0.1)
 -p <port>          Server port (default 6379)
 -s <socket>        Server socket (overrides host and port)
 -a <password>      Password for Redis Auth
 -c <clients>       Number of parallel connections (default 50)
 -n <requests>      Total number of requests (default 100000)
 -d <size>          Data size of SET/GET value in bytes (default 2)
 --dbnum <db>       SELECT the specified db number (default 0)
 -k <boolean>       1=keep alive 0=reconnect (default 1)
 -r <keyspacelen>   Use random keys for SET/GET/INCR, random values for SADD
  Using this option the benchmark will expand the string __rand_int__
  inside an argument with a 12 digits number in the specified range
  from 0 to keyspacelen-1. The substitution changes every time a command
  is executed. Default tests use this to hit random keys in the
  specified range.
 -P <numreq>        Pipeline <numreq> requests. Default 1 (no pipeline).
 -q                 Quiet. Just show query/sec values
 --csv              Output in CSV format
 -l                 Loop. Run the tests forever
 -t <tests>         Only run the comma separated list of tests. The test
                    names are the same as the ones produced as output.
 -I                 Idle mode. Just open N idle connections and wait.

 

I hope you liked this article. You can continue reading more about Redis here. Do watch my Youtube Channel as well for more on Redis Videos.

Get any of the courses at a very special price. The offer is available only for a limited time.

Scroll to Top