Testing Redis Performance Using redis-benchmark
The Redis client includes redis-benchmark, a performance testing utility that simulates N clients concurrently sending M number of query requests.
This section describes how to use redis-benchmark to test the performance of a DCS Redis instance when running command SET or GET in a high-concurrency scenario.
Test Procedure
- Create a DCS Redis instance.
- Create three ECSs and configure the same AZ, VPC, subnet, and security group for the ECSs and the instance.
Only one ECS is required for testing on a single-node or master/standby instance.
- Install redis-benchmark on each ECS. The Redis server can be installed in either of the following ways and benchmark will be installed, too.
- Method 1:
- Download a Redis client. This example uses redis-6.0.9.
- Decompress the client installation package.
- Go to the src directory of redis-6.0.9.
cd redis-6.0.9/src
- Compile the source code.
After the compilation is complete, the tool is stored in the src directory of redis-x.x.x.
- Check whether the redis-benchmark executable file exists.
- Install the tool in the system.
- Method 2:
Install the Redis server matching the ECS OS. The following examples use Ubuntu and CentOS.
- Ubuntu
sudo apt update sudo apt install redis-server
- CentOS
sudo yum install epel-release sudo yum update sudo yum -y install redis
- Ubuntu
- Method 1:
- Run the following test command on all ECSs:
redis-benchmark -h {IP} -p {Port} -a {password} -n {nreqs} -r {randomkeys} -c {connect_number} -d {datasize} -t {command}
Reference values: -c {connect_number}: 200; -n {nreqs}: 10,000,000; -r {randomkeys}: 1,000,000; -d {datasize}: 32
- -h: instance domain name or IP address
- -p: port of the instance. The default value is 6379.
- -a: password for connecting to the instance. This parameter is not required for password-free instances.
- -t Set of commands to be executed For example, to test only the set command, use -t set. To test the ping, get, and set commands, use -t ping,set,get. Use commas (,) to separate commands.
- -c number of client connections
- -d size of a single data record in bytes
- -n number of test packets
- -r number of random keys
- Repeat 4 with different client connections to obtain the maximum QPS (Query per Second, number of read and write operations per second).
- The sum of operations per second of all the three ECSs indicates the performance of the instance specification.
To test on a Redis Cluster instance, launch two benchmark tools on each ECS.
- Add the --cluster parameter only when testing Redis Cluster instances using redis-benchmark.
- In a test for the maximum number of connections of a Redis Cluster instance, if the performance of the ECSs is insufficient, the program will exit or the error message "Cannot assign requested address" will be displayed when the number of connections reaches 10,000. In this case, check how many ECSs are used in the test. Prepare three ECSs and start three redis-benchmark processes on each ECS.
Common redis-cli Options
- -h <hostname>: host name of the server, which can be an IP address or a domain name.
- -p <port>: port of the server. The default value is 6379.
- -a <password>: password for connecting to the server. This parameter is not required for password-free instances.
- -r <repeat>: number of times that a command is run.
- -n <db>: DB number. The default value is 0.
- -c: cluster mode (with -ASK and -MOVED redirections).
- --latency: a loop where latency is measured continuously.
- --scan: scans the key space without blocking the Redis server. (By contrast, scanning using KEYS * blocks Redis server).
- --eval <file>: sends the EVAL command using a Lua script.
- -x: reads the last parameter in stdin.
- --bigscan: scans big keys in the data set.
- --raw: forces raw data output from the hexadecimal format, such as \xe4\xb8.
For more information about redis-cli, visit https://redis.io/docs/connect/cli/
Examples of Common redis-cli Commands
- Connect to an instance:
- Connect to a specified DB:
- Connect to a Redis Cluster instance:
- Test the latency (by sending the ping command):
./redis-cli -h {IP} -p 6379 --latency
- Scan for keys that match the specified pattern:
Common Options in redis-benchmark (redis-6.0.9)
- -h <hostname>: host name of the server, which can be an IP address or a domain name.
- -p <port>: port of the server. The default value is 6379.
- -a <password>: password for connecting to the server. This parameter is not required for password-free instances.
- -c <clients>: number of concurrent connections. The default value is 50.
- -n <requests>: total number of requests. The default value is 100000.
- -d <size>: data size of the SET/GET value, in bytes. The default value is 2.
- --dbnum <db >: database number. The default value is 0.
- --threads <num>: multi-thread mode, which is supported only by redis-benchmark compiled in Redis 6.0. In pressure tests, the multi-thread mode outperforms the single-thread mode.
- --cluster: cluster mode (required only by Redis Cluster).
- -k <boolean>: 1=keep alive; 0=reconnect. The default value is 1, indicating that both pconnect and connect can be tested.
- -r <keyspacelen>: uses random keys for SET, GET, and INCR, and random values for SADD. keyspacelen indicates the number of keys to be added.
- -e: displays server errors to stdout.
- -q: displays only the number of queries per second.
- -l: runs tests in loops.
- -t <tests>: tests specified commands.
- -I : idle mode. Open N idle connections and wait.
- -P <numreq>: concurrent pipeline requests. The default value is 1.
For more information about redis-benchmark, visit https://redis.io/docs/latest/operate/oss_and_stack/management/optimization/benchmarks/.
Examples of Common redis-benchmark Commands
- Test single-node, master/standby, read/write splitting, and Proxy Cluster instances:
./redis-benchmark -h {IP address or domain name} -p 6379 -a {password}--threads {num} -n { nreqs } -r { randomkeys } -c {clients} -d {datasize} -t {command}
- Test Redis Cluster instances:
./redis-benchmark -h {IP address or domain name} -p 6379 -a {password}--threads {num} -n { nreqs } -r { randomkeys } -c {clients} -d {datasize} --cluster -t {command}
- Test connect:
./redis-benchmark -h {IP address or domain name} -p 6379 -a {password}--threads {num} -n { nreqs } -r { randomkeys } -c {clients} -d {datasize} -k 0 -t {command}
- Test idle connections:
./redis-benchmark -h {IP address or domain name} -p 6379 -a {pwd} -c {clients} -I
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot