A redis-benchmark run on the Redis server's own host reports 1.5 million SET requests per second; which flags shaped that figure, and what did it actually measure?
answer
- what did -P do to it
- tiny value, one key, no network
- client and server share a machine
- --threads belongs to the client
- take the flags from production
basics
~20 sA figure like that normally comes from -P. With other defaults it measured pipelined SETs of a 3-byte value on one key over loopback, client and server sharing a machine: true of that shape, not of production traffic.
solid answer
~50 s`-P` is the main lever: each connection sends that many commands before waiting, so fewer round trips and fewer reads per command. The Redis docs show about 1.5 million `SET` per second with `-P 16`. The rest of the shape comes from the defaults: `-c 50` connections, a 3-byte value from `-d`, and one key because `-r` is absent. Running on the server's host means loopback, no real network latency or bandwidth limit, and the client sharing a CPU with the server. So it measured that synthetic shape on that machine, which is worth having for comparing two configurations, but it isn't this application's capacity. To make it honest, I run from an application host and take `-c`, `-d`, `-r`, `-t` and `-P` from production readings. `--threads` adds threads to the benchmark client, not the server. I also never point it at production, because it writes keys and leaves them.
code
bash · 5 lines# The shape behind the headline figure
redis-benchmark -t set -n 1000000 -P 16 -q
# Closer to one application: separate host, its concurrency, value size and keyspace
redis-benchmark -h 10.0.1.5 -t get,set -c 200 -n 1000000 -d 512 -r 1000000 --threads 4go deeper
Recall that redis-benchmark is a load generator shipped with Redis, that -c sets connections, -n sets requests, and that -t selects which tests to run.
Explain how -P raises throughput by saving round trips, how -d and -r change what is measured, and what the defaults are when you pass no flags.
Say what a given figure measured, including loopback, client saturation and batch latency under -P, and rebuild the run from production readings rather than arguing about the number.
Require every quoted benchmark figure to carry its flags, its network path and its server settings, because a number without those cannot support any decision.
## What redis-benchmark does `redis-benchmark` opens a number of connections to a server, sends commands as fast as it can and reports throughput and latency. It is a load generator shipped with Redis. It defaults to `127.0.0.1:6379`, and a full run works through a fixed list of tests: `PING`, `SET`, `GET`, `INCR`, list, set, hash, sorted set and stream commands, one after another. ## The flags that shape the number | Flag | Default | What it changes | |---|---|---| | `-t` | All tests | Which tests run, such as `-t set,get`; ignored if you give a command on the line | | `-c` | 50 | Parallel connections | | `-n` | 100000 | Total requests in each test | | `-d` | 3 | Value size in bytes for `SET` and `GET` | | `-r` | Off | Random keys from a range; without it, every command uses the same key | | `-P` | 1 | Commands sent per connection before waiting for their replies | | `--threads` | Off | Threads inside the benchmark client | | `-q` | Off | Prints only throughput and p50 per test | The Redis docs' own example of `-P 16` reports `SET: 1536098.25 requests per second`, so a figure in the millions is the expected shape of a pipelined run and not a sign of a bug. ## Why -P moves it so far Without pipelining, each connection sends one command and waits, which costs a round trip and usually a read call per command. With `-P 16`, one write and one round trip carry 16 commands. That is a real and useful technique, but the comparison is only fair if your application pipelines to a similar depth. The docs advise using roughly the average pipeline length your application will actually achieve. Redis 8.10's `INFO stats` approximates that with `avg_pipeline_length`, commands parsed per batch across the server. The current docs list the measure as `commands_per_parse_batch_avg`, so read the name from your own server. Latency also changes meaning under `-P`. The client records one value per batch, the time from sending it to the first read event, and uses that same value for every reply in the batch. So the `p50` is a batch figure. ## What the run on the server's host left out - **The network.** Loopback adds almost no latency and has no network card to fill. The docs note that in many real scenarios throughput is limited by the network well before the CPU: 4 KB values at 100,000 per second need about 3.2 Gbit/s. - **Value sizes.** 3 bytes is probably smaller than anything you store. - **The keyspace.** One key rather than many, and a small dataset. The docs also note that most benchmarks do not run long enough to produce significant external fragmentation. - **The command mix.** Each test runs one command type alone, so an expensive command in real traffic never competes with the others. - **Background work.** Unless a save or rewrite happens during the run, there is no fork. Read the `host configuration "save"` and `"appendonly"` lines in the full output to see what the server had set. - **A separate client.** Client and server compete for CPU on the same box. The bottleneck may be the benchmark itself. So the figure is true, and it is true of this shape on this machine. ## --threads is not what it looks like `--threads` runs the benchmark client's event loops on several threads, and it does nothing to the server. It matters when the client is the limit. `redis.conf` notes that to see a speedup from the server's `io-threads`, you must also run the benchmark with `--threads`, or you will not be able to notice the improvement. A flat result may therefore mean only that your client was saturated. ## A more honest run 1. Use a test instance, never production. The tool writes keys such as `key:__rand_int__`, `counter:__rand_int__` and `mylist`, and it does not clean them up. 2. Run from a separate host on the same network path as your application. 3. Take `-c` from `connected_clients`, `-d` from your real values, `-r` from your key count, `-P` from your observed depth and `-t` from your `commandstats` mix. 4. Drop `-q` so you can see the higher percentiles. 5. Watch CPU on the client host, and add `--threads` if it is the one that is saturated. 6. Keep `MONITOR` off. Redis's guide says it significantly affects the measured performance. Even then, it remains a synthetic test, which is why it is best used to compare configurations.
- Your benchmark result barely changes after enabling io-threads on the server. What do you check first?Check whether the benchmark client is the limit. Without `--threads`, it runs on a single event loop, and `redis.conf` warns that you will not notice a speedup unless the benchmark's threads match the server's. Look at the client host's CPU, rerun with `--threads`, and only then conclude anything about the server.
- Why not just run redis-benchmark against production for a truly realistic reading?It writes to the keyspace, using keys like `key:__rand_int__` and `mylist`, and does not remove them. It also takes server capacity from real users, so you would disturb the system you are measuring and pollute its data. Run it against a separate instance on matching hardware instead.
A car's top speed on an empty test track is real and useful for comparing two cars, but it tells you little about how long your commute takes.
- A million-plus requests per second from redis-benchmark must be a bug or a lie.
- redis-benchmark --threads makes the Redis server itself use more threads.
- With no -r, redis-benchmark spreads its commands over many random keys.
- A pipelined run's p50 is the latency of each individual command.
- Loopback results predict throughput over a real network if you keep the same flags.
- redis-benchmark cleans up its test keys, so running it on production is harmless.
Assumes Redis 8.10.3, whose source prints avg_pipeline_length in INFO stats; the current docs list the same measure under another name, so read your own server's output.