fix: stagger browser restarts to prevent simultaneous QUEUE_FULL
Some checks failed
Deploy to Staging / build-and-deploy (push) Failing after 10m37s
Some checks failed
Deploy to Staging / build-and-deploy (push) Failing after 10m37s
- Only allow one browser to restart at a time in acquirePage() - Stagger initial lastRestartTime by RESTART_AFTER_MS/BROWSER_COUNT per instance
This commit is contained in:
parent
713cc30ac7
commit
e49c4073f8
1 changed files with 5 additions and 2 deletions
|
|
@ -56,9 +56,11 @@ function pickInstance(): BrowserInstance | null {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function acquirePage(): Promise<{ page: Page; instance: BrowserInstance }> {
|
export async function acquirePage(): Promise<{ page: Page; instance: BrowserInstance }> {
|
||||||
|
const anyRestarting = instances.some(i => i.restarting);
|
||||||
for (const inst of instances) {
|
for (const inst of instances) {
|
||||||
if (!inst.restarting && (inst.jobCount >= RESTART_AFTER || Date.now() - inst.lastRestartTime >= RESTART_AFTER_MS)) {
|
if (!inst.restarting && !anyRestarting && (inst.jobCount >= RESTART_AFTER || Date.now() - inst.lastRestartTime >= RESTART_AFTER_MS)) {
|
||||||
scheduleRestart(inst);
|
scheduleRestart(inst);
|
||||||
|
break; // only restart one at a time
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -130,7 +132,8 @@ export async function initBrowser(): Promise<void> {
|
||||||
args: ["--no-sandbox", "--disable-setuid-sandbox", "--disable-gpu", "--disable-dev-shm-usage"],
|
args: ["--no-sandbox", "--disable-setuid-sandbox", "--disable-gpu", "--disable-dev-shm-usage"],
|
||||||
});
|
});
|
||||||
const pages = await createPages(browser, PAGES_PER_BROWSER);
|
const pages = await createPages(browser, PAGES_PER_BROWSER);
|
||||||
instances.push({ browser, availablePages: pages, jobCount: 0, lastRestartTime: Date.now(), restarting: false, id: i });
|
const staggerMs = i * (RESTART_AFTER_MS / BROWSER_COUNT);
|
||||||
|
instances.push({ browser, availablePages: pages, jobCount: 0, lastRestartTime: Date.now() + staggerMs, restarting: false, id: i });
|
||||||
}
|
}
|
||||||
logger.info(`Browser pool ready (${BROWSER_COUNT}×${PAGES_PER_BROWSER} = ${BROWSER_COUNT * PAGES_PER_BROWSER} pages)`);
|
logger.info(`Browser pool ready (${BROWSER_COUNT}×${PAGES_PER_BROWSER} = ${BROWSER_COUNT * PAGES_PER_BROWSER} pages)`);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue