Files
indiekit-server/scripts/patch-microsub-batch-concurrency.mjs
Sven c034bcbe35
Deploy Indiekit Server / deploy (push) Successful in 1m20s
perf: reduce microsub BATCH_CONCURRENCY 5→3 to smooth CPU spikes
Feed polling was causing 20-35% CPU and 187ms p99 event loop lag during
batch cycles. 9 active feeds at 16-32min tiers drive ~18 fetches/hour;
concurrent XML parsing at 5-way concurrency was the bottleneck.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-12 22:13:13 +02:00

62 lines
1.7 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* Patch: reduce microsub feed polling batch concurrency from 5 to 3.
*
* With 50 subscribed feeds and 9 at low tiers (1632 min refresh), concurrent
* XML/JSON parsing drives p99 event loop lag to ~187ms and sustained CPU to
* 2035%. Reducing BATCH_CONCURRENCY from 5 to 3 smooths the spikes without
* affecting throughput (scheduler runs every 60s; typical cycle processes 14
* 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`);
}