perf(command-bus)!: store pending commands in a single Redis hash - #2269
Open
osbre wants to merge 4 commits into
Open
perf(command-bus)!: store pending commands in a single Redis hash#2269osbre wants to merge 4 commits into
osbre wants to merge 4 commits into
Conversation
PHPUnit only displayed warnings, so emitted diagnostics (an unsuppressed `unserialize()` on a corrupt payload, for one) passed unnoticed.
Drop the unrelated-keys test, which no longer covers a real path now that reads are scoped to a single hash, and isolate Redis config the way RedisTest does.
osbre
force-pushed
the
perf/redis-command-repository-hash
branch
from
September 1, 2026 18:45
e828236 to
1b81865
Compare
brendt
requested changes
Sep 2, 2026
brendt
left a comment
Member
There was a problem hiding this comment.
The only thing that's inconvenient is the manual migration.
Can we make it so that this command is run once automatically when command:monitor start and when it hasn't migrated yet?
Contributor
Author
|
@brendt Thanks, added. Is the |
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.
Follow-up on #2247 (redis implementation).
RedisCommandRepositorykept one key per command, so every read ranSCAN ... MATCH command:pending:*- which walks every key in Redis.command:monitordoes that twice a second, andkv-storeshares one Redis with the cache, so most of the work was stepping over unrelated cache keys.Pending and failed commands now live in one hash each, read with
HSCAN. The publicCommandRepositoryinterface is unchanged.store()SET command:pending:{uuid}HSETgetPendingCommands()SCAN+ oneGETper commandHSCANloop (COUNT 500)findPendingCommand()GET command:pending:{uuid}HGETmarkAsDone()UNLINK command:pending:{uuid}HDELmarkAsFailed()EXISTS+RENAMEHGET+HSET/HDEL)Two fixes came along with it:
markAsFailed()sentEXISTSthenRENAMEas two calls, and threw if amarkAsDone()landed in between. It is now one script.unserialize()warns and returnsfalseon a corrupted payload rather than throwing, so the oldcatch (Throwable)never caught anything. Handled inunserializeCommand(), withfailOnWarning="true"added tophpunit.xml.dist.Benchmarks
Rows 2 and 4 are the point: same backlog, but 100,000 unrelated cache keys make the old version twice as slow.
Redis 7 in Docker on macOS, median of 15 runs, ~0.5 ms round trip.
redis-command-repository-bench.php
Requires
ext-redisand a throwaway Redis server on127.0.0.1:6399(callsFLUSHALL):Migration
Needed only if the queue isn't empty when you deploy:
Scanning is client-side so each move stays atomic without a script that blocks the server, and
also because Redis before 7 refuses to write after a
SCAN.Notes
HSCANinsteadHGETALL.HGETALLis ~2× faster, but it reads the whole hash in one command, and Redis is single threaded - a big backlog makes every other client wait.HSCANreads in batches of 500 that others can be served between.Tests
Integration tests alongside the three existing ones, which now share a pinned Redis database, hoisted fixtures, and suppressed event handling: the single-hash layout, the atomic move to the failed hash, marking an unknown uuid as failed, corrupted payloads on both read paths, and a 1,200-command backlog that forces
HSCANthrough more than one batch. Skipped when Redis isn't reachable.