perf: move log receiver processing to a worker thread#617
Draft
garrappachc wants to merge 4 commits into
Draft
Conversation
Contributor
Playwright test resultsDetails
|
UDP parsing, regex game-event matching, and MongoDB log writes now run on a dedicated worker thread (node:worker_threads) with its own MongoClient and a second OTEL SDK instance for metrics. The main event loop only calls events.emit() when the worker posts a matched game event via postMessage, eliminating per-log-line synchronous work from the main thread. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
b41fa35 to
ba97136
Compare
Add `log_receiver.use_worker_thread` boolean config (default: false) so the worker thread path can be tested per-deployment before rolling out globally. Restores the original inline UDP + gamelog:message path as the default. Also fixes pre-existing lint errors in worker-message.ts and log-receiver.worker.ts. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ver worker Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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
node:worker_threadsworker with its ownMongoClientand a second OTEL SDK instance for metricsString.includes) before attempting regex matches, skipping >90% of log lines (e.g.shot_fired,damage,picked up item) with near-zero costevents.emit()when the worker posts a matched game event viapostMessage— it does zero work per log line otherwiseControlMessageto the worker on app close; worker drains, closes the socket/MongoDB, shuts down OTEL, then exitsMotivation
During active games the log receiver was causing p99 event loop delay spikes (up to ~20ms). A sample game log had ~21k lines, of which ~19k were high-frequency noise events that still triggered 13 synchronous regex checks each on the main thread.
Test plan
pnpm test— all existing tests passlog receiver worker listening at ...in stdout)tf2pickup.log_receiver.message.countandtf2pickup.games.events.countstill appear in Grafana🤖 Generated with Claude Code