perf(hub): stop heartbeat replay from scanning session history - #1745
Open
ZJUFangzh wants to merge 1 commit into
Open
perf(hub): stop heartbeat replay from scanning session history#1745ZJUFangzh wants to merge 1 commit into
ZJUFangzh wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Findings
- None.
Summary
- Review mode: initial
- No issues found in the added or modified lines. Residual operational risk: the v25→v26 upgrade builds the partial index synchronously during Hub startup; this review did not execute the PR code to measure migration time on a large database.
Testing
- Not run (automation). At review time, the integration check passed; the main test and PR-review checks were pending.
HAPI Bot
Open
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
Fixes #1689.
Root cause
Each CLI
session-aliveheartbeat callsreplayImmediateQueuedMessages(). The existing order checkedisOpenCodeClearDeliveryGated()first, which scans all session metadata in the namespace even when there is nothing to replay. With many connected sessions, that turns the 2-second heartbeats into repeated namespace-wide scans.Moving the queue lookup first removes that scan from the empty-queue path. The queue lookup itself previously had no index matching all of its predicates, so this PR also adds
idx_messages_immediate_queuedon(session_id, seq)with the exact partial predicate used by the query.Production validation
The same change is running on a self-hosted v0.29.0 hub with 123 sessions and 322,007 messages:
/health: timeout/unresponsive -> 3-4 msRecv-Q=0)Testing
bun typecheckbun run testEXPLAIN QUERY PLANuses the new partial index