(draft) perf: fast-path execution for simple read-only commands (+24% throughput)#4018
Draft
rainsupreme wants to merge 1 commit into
Draft
(draft) perf: fast-path execution for simple read-only commands (+24% throughput)#4018rainsupreme wants to merge 1 commit into
rainsupreme wants to merge 1 commit into
Conversation
|
Important Review skippedIgnore keyword(s) in the title. ⛔ Ignored keywords (1)
Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
5f70f74 to
3d28e97
Compare
Add a fast execution path in processCommand() that bypasses call() for eligible read-only commands. This eliminates per-command overhead from module event dispatch, propagation logic, monitor feeding, client-side caching tracking, debug assertions, command tracing, and most timing — while preserving statistically accurate telemetry via 1-in-64 sampling. Eligibility conditions (all must be true): - CMD_READONLY | CMD_FAST (O(1)/O(log N) read commands: GET, HGET, etc.) - No module command-result listeners subscribed - No MONITOR clients connected - Client-side caching tracking not active on this client - Top-level execution (not nested) Sampling strategy (every 64th fast-path command): - Full ustime() timing pair — duration feeds commandlog + histogram - real_cmd->microseconds extrapolated ×64 (preserves usec_per_call avg) - Latency histogram receives real (non-extrapolated) duration - zmalloc peak memory check - afterCommand() cleanup Non-sampled commands (63/64): - cmd->proc(c) executes directly with minimal setup - cmd->calls++ and stat_numcommands++ always updated - failed_calls tracked on deferred errors - No timing, no zmalloc, no commandlog, no afterCommand Measured: +18-21% throughput on ARM Graviton 3, GET 16B t9-p10. Covers ~80-95% of commands in typical caching workloads. Signed-off-by: Rain Valentine <rsg000@gmail.com>
3d28e97 to
1d750e3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add a fast execution path in
processCommand()that bypassescall()for eligible read-only commands, delivering +24% throughput on ARM Graviton 3 (GET 16B, io-threads=9, P=10).What it does
For commands that are
CMD_READONLY | CMD_FAST(GET, HGET, MGET, EXISTS, TTL, etc.) when no features requiring the fullcall()ceremony are active, execute the command handler directly with minimal overhead:cmd->proc(c)+calls+++stat_numcommands+++ commandlog check. No timing, no zmalloc, no afterCommand.usec_per_callin INFO.Why it's ~24% faster
Analysis: Why ~24% faster
CPU flamegraph profiling on the main thread reveals that for a simple
GET, the per-command ceremony in
call()costs nearly as much as the actualwork (hash lookup + value serialization + reply building):
ustime()timing pair (14ns on ARM)zmalloc_used_memory()afterCommand()+ pending flushcall()flag save/restore + propagation checksmoduleFireCommandResultEventdispatchupdateCommandLatencyHistogramcmd->proc)For O(1) reads like GET, the per-request instruction budget is ~3,200 instructions. The fast path eliminates ~700-800 instructions of ceremony per non-sampled command, which at 2.5M rps and IPC 2.87 directly translates to the observed +24% throughput.
Eligibility conditions
All must be true (falls through to unchanged
call()otherwise):CMD_READONLY | CMD_FASTflags setcommandResultSuccessListeners == 0)execution_nesting == 0)Covers ~80-95% of commands in typical caching workloads.
What's preserved
callsexact,usec_per_callstatistically accurate (1/64 sampling, ~40K samples/sec at 2.5M rps)stat_numcommands: exactWhat's skipped
moduleFireCommandResultEvent(no-op when no listeners)replicationFeedMonitors(no-op when no monitors)trackingRememberKeys(disabled when not tracking)valkey_commands_trace(LTTng, no-op in default builds)zmalloc_used_memoryon 63/64 commandsafterCommandon 63/64 commandsBenchmark results (ARM Graviton 3, c7g.metal)
Config: io-threads=9, P=10, GET 16B real data (pre-populated), 5 reps × 300s, pinned cores 0-8 server / 9-17 client.
Testing
--config io-threads 9(commandlog, io-threads, keyspace, multi, expire)call()for any non-eligible command — zero risk to write paths, transactions, modules, or any non-default configuration