Skip to content

Load test Redis Streams on MaxoPerf

This test measures three things about a Redis Stream under load: how long XADD takes to return (redis send), how fast consumers drain the stream, and how long a message takes from XADD to the moment a consumer group member reads it (redis end-to-end). Producers and consumers run in one Locust file, so a single test shows both sides. Consumer throughput is the number of redis end-to-end samples per second. Redis answers in well under a millisecond on a good network, so the interesting signal is usually how the numbers move as you add load, not their starting values.

  • Your Redis must be reachable from the runners: a public endpoint with auth, or a private datacenter outpost inside your network.
  • taurus.yml installs the redis client (8.1.0) when the test starts, with Taurus’s built-in pip-install service. Nothing is preinstalled on the runner, so runners need outbound HTTPS to PyPI. On a private datacenter without internet access, allow PyPI or your package mirror.
  • Only load a Redis you are authorised to test, and prefer a dedicated instance or a database you can empty afterwards. The test creates a stream called maxoperf-load and a consumer group of the same name.

Save this as locustfile.py. Without any change it runs against a Redis on localhost, so you can try it on your laptop first.

locustfile.py
"""Redis Streams load test for MaxoPerf: producers XADD, consumers measure end-to-end latency.
Connection values come from MaxoPerf secrets bound to this test (Dependencies tab)."""
import json, os, time, uuid
import redis
from locust import User, task, events, constant, constant_throughput
# --- connection (bind as a secret; the default works against a local Redis) ---
URL = os.environ.get("SECRET_REDIS_URL", "redis://localhost:6379/0")
# --- names + load knobs (edit freely; not secrets: secret values are masked in run output) ---
STREAM = "maxoperf-load"
GROUP = "maxoperf-load"
SENDS_PER_USER_PER_SEC = 10 # producer rate per virtual user
MESSAGE_BYTES = 512 # payload size
CONSUMERS = 2 # fixed consumer users (Locust fixed_count)
MAXLEN = 100_000 # approximate trim keeps stream memory bounded
BATCH = 100 # entries per XREADGROUP
STALE_AFTER_S = 60 # skip backlog older than this (left over from a previous run)
STARTED = time.time()
r = redis.Redis.from_url(URL) # one pool per process: each greenlet gets its own connection
def record(name, start, exc=None, size=0): # one result sample under label "redis <name>"
if exc is not None: # bzt's results CSV has no escape char: commas/quotes in errors would crash it
exc = Exception(str(exc).replace(",", ";").replace('"', "'"))
events.request.fire(request_type="REDIS", name=f"redis {name}",
response_time=(time.time() - start) * 1000,
response_length=size, exception=exc, context={})
@events.test_start.add_listener
def create_group(environment, **kw): # idempotent; "$" = only messages sent from now on
try:
r.xgroup_create(STREAM, GROUP, id="$", mkstream=True)
except redis.ResponseError as e:
if "BUSYGROUP" not in str(e):
raise
except redis.RedisError as e:
print(f"setup failed, sends will fail too: {e}")
class Producer(User): # label "redis send" = XADD call duration
wait_time = constant_throughput(SENDS_PER_USER_PER_SEC)
@task
def send(self):
body = json.dumps({"id": str(uuid.uuid4()), "sent_at": time.time(), "pad": "x" * MESSAGE_BYTES})
start = time.time()
try:
r.xadd(STREAM, {"m": body}, maxlen=MAXLEN, approximate=True)
record("send", start, size=len(body))
except (redis.RedisError, OSError) as e:
record("send", start, exc=e)
class Consumer(User): # label "redis end-to-end" = now - sent_at per entry
fixed_count = CONSUMERS
wait_time = constant(0)
def on_start(self):
self.name = f"c-{uuid.uuid4().hex[:8]}"
@task
def receive(self):
try: # blocking read on a gevent-patched socket yields to other users
res = r.xreadgroup(GROUP, self.name, {STREAM: ">"}, count=BATCH, block=1000)
except (redis.RedisError, OSError) as e:
record("end-to-end", time.time(), exc=e)
time.sleep(1) # don't hot-loop failures
return
for _, entries in res:
for _id, fields in entries:
msg = json.loads(fields[b"m"])
if msg["sent_at"] >= STARTED - STALE_AFTER_S:
record("end-to-end", msg["sent_at"], size=len(fields[b"m"]))
r.xack(STREAM, GROUP, *[i for i, _ in entries])
# teardown: bzt gives Locust 10 s to stop (--stop-timeout), so nothing slow belongs here

Upload it together with this taurus.yml. Taurus runs the Locust file and installs the client when the test starts:

taurus.yml
execution:
- executor: locust
scenario: mq
scenarios:
mq:
script: locustfile.py
services:
- module: pip-install
packages:
- redis==8.1.0

Only connection values are secrets. Bound secret values are masked in run output, so the stream and group names stay plain constants at the top of the file; if they were secrets, every error message that mentions them would be garbled.

Secret env varMeaningExample value
SECRET_REDIS_URLRedis URL. Use rediss:// for TLS and redis://:password@host:6379/0 when a password is needed.rediss://:<your-password>@redis.example.com:6379/0

Create the secret and bind it to the test as described in Secrets and environments. The script reads it as an environment variable.

Bind the connection values as secrets; the script reads them as environment variables.
  1. Create a new test. upload taurus.yml and locustfile.py together. taurus.yml is the entry point: it runs the Locust file and installs the client when the test starts.

    Upload taurus.yml and locustfile.py together: Taurus runs the Locust file and installs the client when the test starts.
  2. On the Dependencies tab, bind the SECRET_REDIS_URL secret.

  3. Set the virtual users and duration. Two of the users are always consumers (CONSUMERS), so producers = users minus 2. Ten users for one minute is a good first run: eight producers at 10 messages per second each.

  4. Start the run.

Two labels appear in the results:

  • redis send: the duration of the XADD call. A failed sample means Redis refused or did not answer the write.
  • redis end-to-end: time from the producer’s timestamp to the consumer reading the entry. Its samples per second are your consumer throughput.

A healthy run has about as many redis end-to-end samples as redis send samples and a flat end-to-end line. If end-to-end latency climbs over the run, the consumers are falling behind: add consumers or raise BATCH. Messages that were already more than 60 seconds old when the test started are skipped without a sample, so a backlog left by a previous run does not pollute the numbers.

Sample times are whole milliseconds. A local or same-zone Redis acks in under a millisecond, so you will see 0 to 1 ms there; that is rounding, not a bug.

Redis Streams run: send latency and end-to-end latency side by side (whole milliseconds; local acks round to 0–1 ms).

See Read run results for the rest of the run page.

KnobEffect
MAXLENApproximate stream length cap (XADD ... MAXLEN ~). Lower it to bound memory; trimming costs a little write time. Remove it and an untrimmed stream grows until Redis runs out of memory.
BATCH and blockcount entries per XREADGROUP and how long an empty read waits. Larger batches raise consumer throughput; a long block only delays the end of the test.
CONSUMERSFixed consumer users sharing one group. Each entry goes to exactly one of them. Add consumers when end-to-end latency climbs.
SENDS_PER_USER_PER_SECProducer rate per user. The total rate is producers × this value.
MESSAGE_BYTESPayload size. Use your real size.
PipeliningReal producers often pipeline XADDs. This script sends one per call so redis send is a true per-message latency.
Pending entriesAn entry read but never acked stays in the group’s pending list (XPENDING). If you kill consumers mid-test, inspect it and reclaim with XAUTOCLAIM.
ClusterOne stream lives in one hash slot, so one shard. A single stream cannot spread over a Redis Cluster; to test sharding, use several stream keys.

Run producers and consumers on one runner when you read end-to-end latency. Across several runners the clocks differ, and the skew adds directly to the latency; sync clocks with NTP if you must spread out.

SymptomCause and fix
ConnectionError or timeouts on redis sendThe runners cannot reach Redis. Check the URL, the firewall or security group, and TLS (rediss://). For a private network, use an outpost.
NOAUTH or WRONGPASSThe URL lacks a password or has the wrong one. Put the credentials in the secret value.
NOGROUPThe consumer group was deleted mid-run (a flush, or another tool). Restart the run; the group is recreated at start.
redis end-to-end is emptyThe group is created at the end of the stream ($), so entries sent before it existed are never read. This only happens on the very first warm-up; if it persists, check CONSUMERS is above 0 and the consumers are not failing.
A failed row with no nameAn unhandled exception inside the script. Check the run logs for the traceback.
ModuleNotFoundError: No module named 'redis'The pip-install step could not install the client, usually because the runner has no route to PyPI (common on a private datacenter). Allow outbound HTTPS to PyPI or your mirror, and check the run logs for the pip error.