Repository navigation
perf: write each event batch to a TCP subscriber in one call - #173
Merged
Merged
Conversation
Every TCP Worker subscribes to its queue's events (to report stalled jobs) and a pull or ack batch emits one event per job, so the server wrote events x subscribers frames, one socket write each: about 64% of the server's CPU with four worker processes, and drain throughput fell from 33k jobs/s with one worker process to 18k with four and 10k with eight. The TCP bridge now registers the events manager's batch callback: it encodes each event once, concatenates a batch's frames per queue in batch order and writes them to each subscriber socket in one call. Same bytes and per-socket order; an event that cannot be encoded is skipped alone; the over-budget drop decision is unchanged. Drain with 1/4/8 worker processes: 39.7k/53.1k/40.9k jobs/s. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
This branch was successfully deployed
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
Every TCP Worker subscribes to its queue's events (for
stalled), and pull/ack batches emit one event per job. The server wrote each event to each subscriber with its own socket write: a CPU profile of a 4-process drain showed ~64% of server CPU in nativewriteunderbroadcastBatch→broadcastEvent, and throughput fell as worker processes were added.The TCP bridge now uses the events manager's existing batch-subscriber path: frames are encoded once, concatenated per queue in batch order, and written once per subscriber socket. Same bytes and per-socket order; single events unchanged; an unencodable event is skipped alone; the over-budget drop decision is unchanged (only the logged byte count can be larger).
Native Linux (Debian 13, Ryzen 9 7950X3D, Bun 1.4.4), server pinned to 2 cores, workers on the other CCD,
pollTimeout: 5000, median of 3.Verification
bun run test:sandbox(before the final guard edit): unit 11,471/0 (347 PG skips), TCP 499/0, embedded 342/0; rerun on the final commit in progressNo test changes.
🤖 Generated with Claude Code