Repository navigation
perf(worker): parallelize per-fingerprint issue upserts in telemetry ingest #SUPERLOG - #529
Closed
superlog-app[bot] wants to merge 1 commit into
Closed
superlog-app[bot] wants to merge 1 commit into
superlog-app[bot] wants to merge 1 commit into
Conversation
…ingest #SUPERLOG Delivery-Id: c4caa9ff7979d5d9dfbf59a787d2e50a811d31d337471fcb36e7e1014114d931 Delivery-Base: main
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 telemetry ingest batch is running 9–10 seconds (70% above the 5,618 ms baseline), causing a sustained 13–39 second cursor lag for all tenants. Fingerprinting and issue creation are delayed for every project on the shared worker.
Root cause
flushIssueGroupsinapps/worker/src/telemetry/ingest.tsiterates all distinct fingerprint groups with a sequentialfor…awaitloop, making one blocking Postgres round-trip per group. EachupsertIssuecall runs a multi-CTE SQL statement (~50–100 ms). With 100–200 distinct fingerprints per BATCH_SIZE=500 batch — driven by projectf0686143generating many uniquenot-foundspan fingerprints — the serial round-trips alone consume 5–20 seconds of wall-clock time per batch.ClickHouse P95 (2,049 ms, improved vs baseline) and LLM concurrency (down 80%) are both confirmed not to be the bottleneck. The pattern holds since the current worker boot at 11:17 UTC: lifetime span average = 9,352 ms (sum 12,962,042 ms / count 1,386 batches), log average = 9,843 ms.
The upserts are safe to parallelize: each targets a distinct
(project_id, fingerprint)primary key so there are no intra-batch row conflicts.Remediation
Replace the sequential
for…awaitloop influshIssueGroupswith a bounded concurrent map (UPSERT_CONCURRENCY=8), using the samemapWithConcurrencypattern already established inagent-runs/prompt-context.ts.new/recurredissues sequentially — these pg-boss INSERTs are sparse and fast.Error isolation is preserved: each upsert failure is caught, logged, and counted independently without affecting other groups or the cursor advancement.
Testing
All 11 existing telemetry-ingest unit tests pass, including the NUL-byte isolation test and the fingerprint-collapse test.
Related incident: 9e740fa3-4cdc-4a88-a456-fc2e00644e7e
Was this PR helpful? Leave feedback — goes straight to the Superlog team.
Summary by cubic
Parallelizes the per-fingerprint issue upserts in telemetry ingest so batches stop blocking on sequential Postgres round-trips. This cuts per-batch processing from ~9–10 seconds and removes the sustained 13–39 second cursor lag affecting all tenants.
mapWithConcurrencyhelper (same pattern asagent-runs/prompt-context.ts), leaving headroom in the postgres.js default pool of 10.(project_id, fingerprint)key, so there are no intra-batch row conflicts.Written for commit 9d73f60. Summary will update on new commits.