How to use the command redis-benchmark (with examples)

How to use the command redis-benchmark (with examples)

Redis-benchmark is a tool that allows users to benchmark a Redis server. It can be used to measure the performance of a Redis server by executing various command types and providing statistics.

Use case 1: Run full benchmark

Code:

redis-benchmark

Motivation:

Running a full benchmark without any additional arguments allows users to quickly gauge the overall performance of their Redis server. This is useful when trying to compare the performance of different Redis server instances or to identify potential bottlenecks.

Explanation:

The command redis-benchmark without any arguments is used to run a full benchmark of a Redis server. It will execute a predefined set of commands and measure their execution time. The default number of requests is 100,000.

Example output:

======= Latency =======
      SET: 0.693 ms
      GET: 0.620 ms
...
======= Commands/sec =======
      SET: 143885.51 requests per second
      GET: 160256.41 requests per second
...

Use case 2: Run benchmark on a specific Redis server

Code:

redis-benchmark -h host -p port -a password

Motivation:

Running a benchmark on a specific Redis server allows users to measure the performance of a particular server instance. This is useful when benchmarking multiple servers for comparison or when diagnosing issues with a specific server.

Explanation:

The arguments -h host, -p port, and -a password are used to specify the Redis server to benchmark. The -h argument is followed by the host IP or hostname, the -p argument is followed by the port number, and the -a argument is followed by the password for authentication if required.

Example output:

======= Throughput =======
      SET: 135922.32 requests per second
      GET: 147058.82 requests per second
...

Use case 3: Run a subset of tests with default 100000 requests

Code:

redis-benchmark -h host -p port -t set,lpush -n 100000

Motivation:

Running a subset of tests allows users to focus on specific command types and measure their performance. This can be useful when trying to optimize certain aspects of a Redis server or when testing the impact of specific commands on performance.

Explanation:

The -t set,lpush argument is used to specify the subset of tests to run. In this example, the benchmark will only execute SET and LPUSH commands. The -n 100000 argument is used to specify the number of requests to execute for each test.

Example output:

======= Throughput =======
      SET: 138888.89 requests per second
      LPUSH: 158730.16 requests per second
...

Use case 4: Run with a specific script

Code:

redis-benchmark -n 100000 script load "redis.call('set', 'foo', 'bar')"

Motivation:

Running a benchmark with a specific script allows users to measure the performance of custom Redis Lua scripts. This can be helpful when testing and optimizing the performance of complex Redis operations implemented using Lua scripting.

Explanation:

The -n 100000 argument is used to specify the number of requests to execute. The script load "redis.call('set', 'foo', 'bar')" argument is used to specify the Lua script to execute. In this example, the script simply sets the value of the key “foo” to “bar”.

Example output:

======= Throughput =======
      Generic: 147058.82 requests per second
      Eval: 142857.14 requests per second
...

Use case 5: Run benchmark by using 100000 random keys

Code:

redis-benchmark -t set -r 100000

Motivation:

Running a benchmark with random keys can simulate real-world scenarios where the Redis server needs to handle various key value pairs. This can be useful when trying to evaluate the performance of a Redis server under different load patterns.

Explanation:

The -t set argument is used to specify the test to run, in this case, the SET command. The -r 100000 argument is used to specify the number of random keys to use. Each request will select a random key from a pool of keys.

Example output:

======= Throughput =======
      SET: 153846.15 requests per second
...

Use case 6: Run benchmark by using a Pipelining of 16 commands

Code:

redis-benchmark -n 1000000 -t set,get -P 16

Motivation:

Running a benchmark with a pipelining of commands can increase the throughput and measure the performance of the Redis server under high-load scenarios. This can be useful when testing the limits of a Redis server or when comparing the performance of different server configurations.

Explanation:

The -n 1000000 argument is used to specify the number of requests to execute. The -t set,get argument is used to specify the subset of tests to run, in this case, the SET and GET commands. The -P 16 argument is used to specify the number of commands to pipeline. In this example, every request will include 16 commands.

Example output:

======= Throughput =======
      SET: 127388.53 requests per second
      GET: 370370.37 requests per second
...

Use case 7: Run benchmark quietly and only show query per seconds result

Code:

redis-benchmark -q

Motivation:

Running a benchmark quietly allows users to quickly see the query per seconds result without any additional information or statistics. This can be useful when only interested in the overall performance of the Redis server and not the detailed benchmark results.

Explanation:

The -q argument is used to run the benchmark quietly. It only displays the query per second result for each command and suppresses any additional information or statistics.

Example output:

       SET: 139860.14 requests per second
       GET: 148058.36 requests per second
...

Conclusion:

The redis-benchmark command is a powerful tool for benchmarking a Redis server. It allows users to measure the performance of a Redis server by executing various command types and provides detailed statistics. Whether running a full benchmark, testing specific command types, using custom scripts, or simulating different load scenarios, redis-benchmark provides the flexibility to evaluate and optimize the performance of Redis servers.

Related Posts

How to use the command pg_dumpall (with examples)

How to use the command pg_dumpall (with examples)

The pg_dumpall command is used to extract an entire PostgreSQL database cluster, including all databases, into a script file or other archive file.

Read More
How to use the command `ed` (with examples)

How to use the command `ed` (with examples)

ed is the original Unix text editor. It is a line-oriented editor used for creating and modifying text files.

Read More
How to use the command gv2gml (with examples)

How to use the command gv2gml (with examples)

The gv2gml command is a part of the Graphviz software package and is used to convert a graph from .

Read More