How to Use the Command 'redis-benchmark' (with Examples)

How to Use the Command 'redis-benchmark' (with Examples)

The redis-benchmark command is a versatile tool that enables users to measure the performance of their Redis server. By simulating various usage scenarios, this command allows you to analyze the speed and efficiency of Redis operations under different loads and configurations. Whether it is configuring the server for a specific workload or testing on different infrastructure setups, redis-benchmark provides detailed insights and performance metrics.

Use Case 1: Run Full Benchmark

Code:

redis-benchmark

Motivation:

Running a full benchmark provides a comprehensive overview of the Redis server’s performance. This is critical for obtaining a baseline metric, which can be compared over time or across different configurations to identify anomalies or areas for improvement.

Explanation:

  • redis-benchmark: Executes a full suite of default tests on the locally accessible Redis server. It does not require additional arguments as it tests the server with default settings and operations.

Example Output:

PING_INLINE: 1544444.50 requests per second
PING_BULK: 1545645.50 requests per second
SET: 973972.25 requests per second
GET: 1658374.63 requests per second
INCR: 1655629.38 requests per second

Use Case 2: Run Benchmark on a Specific Redis Server

Code:

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

Motivation:

When managing multiple Redis instances or testing remote servers, it is crucial to benchmark a specific server. This can help in comparing performance across different environments, such as development, staging, and production servers, allowing fine-tuning for each specific setup.

Explanation:

  • -h host: Specifies the hostname or IP address of the Redis server.
  • -p port: Defines the port number on which the Redis server is running.
  • -a password: Provides authentication to the server, if it is password-protected, ensuring the benchmark tests are authorized.

Example Output:

PING_INLINE: 1456783.25 requests per second
PING_BULK: 1490673.50 requests per second
SET: 943872.25 requests per second
GET: 1529374.63 requests per second
INCR: 1535629.38 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:

Targeting specific Redis operations helps pinpoint performance issues or optimization areas for those commands. This might be useful when you know the application heavily uses certain commands and wish to focus on tuning those areas for better performance.

Explanation:

  • -h host -p port: Connect to the specified Redis server.
  • -t set,lpush: Selects a subset of tests; in this case, it benchmarks the set and lpush operations to measure their specific performance.
  • -n 100000: Specifies the total number of requests for the benchmark, ensuring a thorough test run.

Example Output:

SET: 980129.56 requests per second
LPUSH: 830472.90 requests per second

Use Case 4: Run with a Specific Script

Code:

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

Motivation:

When introducing custom scripts into your Redis instance, it’s important to understand the performance impact. This command allows you to benchmark how well custom Lua scripts perform under load, which can guide decisions around script optimization.

Explanation:

  • -n 100000: The number of iterations for the script provided, ensuring statistically significant results.
  • script load "redis.call('set', 'foo', 'bar')": Loads and benchmarks a Lua script — in this example, a script that sets a key foo to a value bar.

Example Output:

EVAL: 774823.76 requests per second

Use Case 5: Run Benchmark Using 100000 Random Keys

Code:

redis-benchmark -t set -r 100000

Motivation:

Testing with random keys simulates a more realistic access pattern, reflecting the operational data load more accurately, especially in environments with large datasets. The randomness can expose potential bottlenecks or irregularities not visible with sequential or less varied data.

Explanation:

  • -t set: Chooses to only benchmark the set operation.
  • -r 100000: Uses 100000 random keys, adding variability to the data written to the database and allowing the identification of performance differences due to key size variations.

Example Output:

SET: 907834.23 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:

Pipelining enables clients to pack multiple commands into a single request, reducing latency by minimizing back-and-forth communication delay. Evaluating pipelined operations helps in understanding performance gains from reducing round trips, crucial for applications that batch multiple operations.

Explanation:

  • -n 1000000: Executes a million requests, sufficient to assess the effectiveness of pipelining.
  • -t set,get: Benchmarks both set and get operations to see their pipelined performance.
  • -P 16: Uses pipelining with 16 commands per request, optimizing throughput by decreasing command-handling latency.

Example Output:

SET: 1213420.89 requests per second
GET: 1342820.12 requests per second

Use Case 7: Run Benchmark Quietly and Only Show Query Per Seconds Result

Code:

redis-benchmark -q

Motivation:

In scenarios where concise results are required, such as automated scripts or quick checks, the quiet mode provides a succinct output focused solely on performance metrics. This can be particularly advantageous for quickly assessing server health or comparing simple benchmarks without needing detailed logs.

Explanation:

  • -q: Activates quiet mode, suppressing detailed output and displaying only the query per second results for each test, ideal for fast assessments.

Example Output:

PING_INLINE: 1432134.23 requests per second
PING_BULK: 1451234.76 requests per second
SET: 953671.12 requests per second
GET: 1534921.47 requests per second

Conclusion:

Utilizing the redis-benchmark tool can significantly aid in evaluating and optimizing Redis server performance across various scenarios. By understanding different use cases and corresponding command options, users can tailor their benchmarking efforts to suit specific needs, facilitating targeted performance improvements and broader system efficiency.

Related Posts

How to use the command 'genie' (with examples)

How to use the command 'genie' (with examples)

Genie is a command-line utility designed to facilitate a seamless experience of running systemd under the Windows Subsystem for Linux (WSL).

Read More
How to use the command 'aws route53' (with examples)

How to use the command 'aws route53' (with examples)

The AWS Route 53 CLI is a powerful tool for interfacing with Amazon’s scalable and highly available Domain Name System (DNS) web service.

Read More
How to Use the Command 'aws ecr' (with Examples)

How to Use the Command 'aws ecr' (with Examples)

The AWS Elastic Container Registry (ECR) is a fully managed Docker container registry that makes it straightforward for developers to store, manage, and deploy Docker container images.

Read More