/** * Patch: reduce microsub feed polling batch concurrency from 5 to 3. * * With 50 subscribed feeds and 9 at low tiers (16–32 min refresh), concurrent * XML/JSON parsing drives p99 event loop lag to ~187ms and sustained CPU to * 20–35%. Reducing BATCH_CONCURRENCY from 5 to 3 smooths the spikes without * affecting throughput (scheduler runs every 60s; typical cycle processes 1–4 * feeds anyway). */ import { access, readFile, writeFile } from "node:fs/promises"; const MARKER = "// [patch] microsub-batch-concurrency"; const OLD_SNIPPET = `const BATCH_CONCURRENCY = 5; // Process 5 feeds at a time`; const NEW_SNIPPET = `const BATCH_CONCURRENCY = 3; // Process 3 feeds at a time ${MARKER}`; const candidates = [ "node_modules/@rmdes/indiekit-endpoint-microsub/lib/polling/scheduler.js", "node_modules/@indiekit/indiekit/node_modules/@rmdes/indiekit-endpoint-microsub/lib/polling/scheduler.js", ]; async function exists(filePath) { try { await access(filePath); return true; } catch { return false; } } let applied = 0; let skipped = 0; for (const filePath of candidates) { if (!(await exists(filePath))) continue; const src = await readFile(filePath, "utf8"); if (src.includes(MARKER)) { skipped++; continue; } if (!src.includes(OLD_SNIPPET)) { console.warn( `[patch] microsub-batch-concurrency: upstream format changed in ${filePath}`, ); continue; } await writeFile(filePath, src.replace(OLD_SNIPPET, NEW_SNIPPET), "utf8"); applied++; } if (applied > 0) { console.log( `[patch] microsub-batch-concurrency: applied to ${applied} file(s)`, ); } else if (skipped > 0) { console.log(`[patch] microsub-batch-concurrency: already applied`); }