Skip to content

INFO commandstats counts WAIT and WAITAOF, and times the connection commands (#388) - #568

Merged
murtazayusuf merged 1 commit into
kividbio:masterfrom
matheussilvano:commandstats-wait-waitaof
Nov 15, 2026
Merged

murtazayusuf merged 1 commit into
kividbio:masterfrom
matheussilvano:commandstats-wait-waitaof

Conversation

@matheussilvano

Copy link
Copy Markdown
Contributor

Follow-up to #533, as suggested there. Refs #388.

  • WAIT and WAITAOF, answered in the same match, are now counted like WATCH, HELLO and the rest.
  • The commands the connection loop answers itself are no longer recorded with 0 usec: started is read before the match and usec is what they took (for WAIT and WAITAOF, the time they waited, as Redis counts a blocked command). HELLO times itself the same way. Both I/O models.

Tests: commandstats_count_the_connection_commands (tests/parity.rs) now also checks wait (one call, one with the wrong arity) and waitaof; it fails without the change. cargo fmt --check, cargo clippy --all-targets -- -D warnings (with and without lua,tls), --test parity and --test uring pass. The test does not assert the timing: the calls it makes return at once, so usec would be flaky to check. CLA already signed.

…ommands (kividbio#388)

Follow-up to kividbio#533: the commands answered in the connection loop were recorded with 0 usec, and WAIT and WAITAOF not at all.
@murtazayusuf

Copy link
Copy Markdown
Contributor

Thanks @matheussilvano, and sorry this sat for a while! Counting WAIT and WAITAOF is right, Redis counts both, and timing the connection commands instead of reporting 0 is a nice fix (HELLO 3 now shows ~9 usec here, same as Redis). I checked it against Redis 8.10.3 and measured the hot path. Two things need changing, plus the rebase.

1. WAIT/WAITAOF shouldn't count the time they were blocked. Redis counts the CPU time of the call, not the time a blocked client waited. Same commands sent to Redis 8.10.3, master, and this branch rebased on master:

Redis 8.10.3 master this PR (rebased)
cmdstat_wait after WAIT 0 0, WAIT 1 300 (blocks 300 ms, no replicas), WAIT 0, and one WAIT 0 0 in MULTI/EXEC calls=3,usec=8,rejected_calls=1 calls=1,usec=0 (only the one in EXEC) calls=4,usec=300592,usec_per_call=75148.00,rejected_calls=1
cmdstat_blpop after BLPOP nokey 0.3 usec=19 usec=29 usec=27

So for Redis the 300 ms wait adds nothing, and our BLPOP already leaves its wait out too. With the PR, a few WAITs push usec_per_call into the tens of ms, and INFO latencystats puts wait p99 at about half a second. Can you time only the work around the await? Take the time before wait_for_replicas (and the WAITAOF equivalent) and again after it returns, and record the sum, or record started.elapsed() minus how long the await took. The other commands in that list don't block, so started.elapsed() is fine for them.

2. Rebase on master. It conflicts in server.rs, server_uring.rs and tests/parity.rs. What has to survive:

  • master now has queued_here just above the match (UNWATCH inside MULTI runs at once and drops the watches, so EXEC succeeds after a watched key changed #550/WAIT and WAITAOF inside MULTI run (and block) at once instead of being queued #499). Inside MULTI, WAIT and WAITAOF are queued (+QUEUED), and EXEC answers and counts them (the connection_reply_in_exec branch). If you add them to the matches! list without also adding them to queued_here, the +QUEUED reply gets counted as a call and EXEC counts it again. So: let queued_here = tx.active && matches!(cmd_name.as_str(), "UNWATCH" | "AUTH" | "WAIT" | "WAITAOF");, keep the !queued_here && guard on the record, and put let started = Instant::now(); right after it, before the match. Same in both files.
  • HELLO has moved into commands::login::Login::hello with a single crate::cmdstats::record("HELLO", &cmd, &reply, std::time::Duration::ZERO) in the "HELLO" if !tx.active arm, so your five hello_started hunks don't apply anymore. Just pass started.elapsed() in that one call.
  • tests/parity.rs: keep master's doc comment and the let _stats = stats_lock(); line, then add your lines. It'd be great to also check MULTI / WAIT 0 0 / EXEC counts once, and to add an upper bound on wait's usec after a WAIT 1 200, something like < 100_000. An upper bound won't be flaky, and it would have caught point 1.
  • CHANGELOG.md: git auto-merges your entry into the [1.2.1] section. It belongs under [Unreleased].

I did this rebase locally to test it (not pushed): with the queued_here change, MULTI/WAIT/EXEC counts once and --test parity commandstats passes.

Hot path: fine. started is only read on the slow path, after the fast path has already taken GET/SET/PING. callgrind via scripts/perf/run.sh, io_uring, one thread, instructions per command, master vs master+#568:

workload master #568 diff
GET 100 B 3,291 3,298 +0.2%
SET 100 B 4,027 4,042 +0.4%
GET 1 KB 3,781 3,792 +0.3%
SET 1 KB 4,184 4,177 -0.2%
PING 2,857 2,855 -0.1%

(Fat LTO as shipped, average of two runs each. With LTO off, GET 1 KB moved +2.5% in two of three runs. That's codegen-unit noise from touching handle_client and it goes away with fat LTO.)

One more thing, not for this PR: we count a rejected call in calls too (calls=4,rejected_calls=1 above), while Redis leaves rejected calls out of calls (3). That's in cmdstats::record for every command, so I'll open a separate issue for it.

So: needs the WAIT/WAITAOF timing change and the rebase above, then it's good to go. Thanks again!

@murtazayusuf
murtazayusuf merged commit 549f2f6 into kividbio:master Nov 15, 2026
11 checks passed
@murtazayusuf

Copy link
Copy Markdown
Contributor

Landed as #817, built on your commit (it's in master's history under your name, and the changelog thanks you). We added the two review items ourselves: WAIT/WAITAOF are timed without the blocked time (Redis records ~2 usec for a 500 ms WAIT), and they count once inside MULTI/EXEC. Thanks @matheussilvano!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants