Skip to content

Commit b677219

Browse files
committed
fix: max concurrency for pg
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
1 parent a93f850 commit b677219

4 files changed

Lines changed: 32 additions & 2 deletions

File tree

services/apps/packages_worker/src/bin/blast-radius-worker.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
1-
import { svc } from '../service'
1+
import { Config } from '@crowd/archetype-standard'
2+
import { Options, ServiceWorker } from '@crowd/archetype-worker'
3+
4+
// Own ServiceWorker instance rather than the shared one in ../service (used by every
5+
// other packages_worker entry point) — its activities are CPU/IO-heavy (tarball
6+
// downloads+extraction, agent subprocesses), so it needs a concurrency cap that would
7+
// otherwise throttle unrelated, lightweight ingestion workers if set on the shared
8+
// instance. Left uncapped, the SDK default lets dozens run at once in this one process,
9+
// starving the event loop and missing heartbeat deadlines.
10+
const config: Config = {
11+
envvars: [],
12+
producer: { enabled: false },
13+
temporal: { enabled: true },
14+
redis: { enabled: false },
15+
}
16+
17+
const options: Options = {
18+
postgres: { enabled: false }, // packages-db is managed via getPackagesDb()
19+
maxConcurrentActivityTaskExecutions: 8,
20+
}
21+
22+
const svc = new ServiceWorker(config, options)
223

324
// On-demand only — analyzeBlastRadius is triggered per request from the backend's
425
// submitBlastRadiusJob handler (workflow.start), not on a schedule.

services/apps/packages_worker/src/blast-radius/dependentsScan.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,10 @@ export async function scanDependents(input: {
279279
for (const name of ranked) {
280280
if (analyzed.length >= topN) break
281281

282+
// Phase 1 heartbeats every 200 candidates via mapWithConcurrency; this walk is
283+
// sequential (one packument fetch at a time), so it needs its own heartbeat too.
284+
onProgress?.()
285+
282286
const packument = await fetchPackument(name)
283287
if (isFetchError(packument)) continue
284288

services/apps/packages_worker/src/blast-radius/stages/reachability.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,13 @@ export async function runReachabilityStage(
176176
return
177177
}
178178

179-
// Backoff before retry
179+
// Backoff before retry. Heartbeat partway through — the longest backoff
180+
// (attempt 2, 30s) is still well under the stage's 5-minute heartbeatTimeout
181+
// on its own, but 4 dependents processing concurrently can each be mid-backoff
182+
// at once with nothing else heartbeating in between.
180183
const delayMs = RETRY_BACKOFF_BASE * attempt
181184
await new Promise((resolve) => setTimeout(resolve, delayMs))
185+
onProgress?.()
182186
}
183187
}
184188
} finally {

services/apps/packages_worker/src/blast-radius/workflows.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const { blastRadiusReachability } = proxyActivities<typeof activities>({
3838

3939
const { blastRadiusReport } = proxyActivities<typeof activities>({
4040
startToCloseTimeout: '2 minutes',
41+
heartbeatTimeout: '1 minute',
4142
retry: { maximumAttempts: 3 },
4243
})
4344

0 commit comments

Comments
 (0)