I have an API endpoint that is doing:
const browser = await PuppeteerHelper.launch();
const page = await browser.newPage();
await page.goto(ENDPOINT);
const result = await page.evaluate(async (endpoint) => {
const module = await import(`${endpoint}/resource.js`);
const result = await module.execute();
return result;
}, ENDPOINT);
await browser.close();
return result;
Although this endpoint is “private” and should only be hit a small number of times, I am finding the server melting down and when I run top I see:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
130 root 20 0 0 0 0 R 97.9 0.0 8,13 kswapd0
3513310 root 19 -1 33.0g 195708 0 S 29.1 0.3 7,38 chrome
3392579 root 19 -1 32.9g 58032 0 S 23.2 0.1 10,45 chrome
3265281 root 19 -1 32.9g 58056 0 S 22.6 0.1 16,18 chrome
3514710 root 19 -1 33.0g 195688 0 S 22.6 0.3 7,39 chrome
3514664 root 19 -1 33.0g 195748 0 S 19.0 0.3 7,37 chrome
3268532 root 19 -1 32.9g 58064 0 S 18.7 0.1 15,58 chrome
3263718 root 19 -1 32.9g 58276 0 S 15.9 0.1 16,43 chrome
3325663 root 19 -1 32.9g 58108 0 S 15.9 0.1 12,50 chrome
3516448 root 19 -1 33.0g 195604 0 S 15.9 0.3 7,36 chrome
3516467 root 19 -1 33.0g 195604 0 S 15.6 0.3 7,36 chrome
3269987 root 19 -1 32.9g 58072 0 S 15.3 0.1 15,51 chrome
3263675 root 19 -1 32.9g 58040 0 S 15.0 0.1 16,43 chrome
3511548 root 19 -1 33.0g 195444 0 S 14.1 0.3 7,41 chrome
3330812 root 19 -1 32.9g 58016 0 S 13.1 0.1 12,40 chrome
3796523 root 20 0 0 0 0 I 13.1 0.0 0:32.83 kworker/u32:2-flush-9:3
3325696 root 19 -1 32.9g 58068 0 S 12.2 0.1 12,51 chrome
3513362 root 19 -1 33.0g 195568 0 S 12.2 0.3 7,41 chrome
3516446 root 19 -1 33.0g 195684 0 S 11.9 0.3 7,36 chrome
3514857 root 19 -1 33.0g 195672 0 S 11.6 0.3 7,38 chrome
3511584 root 19 -1 33.0g 195552 0 S 11.3 0.3 7,42 chrome
3270066 root 19 -1 32.9g 58008 0 S 9.2 0.1 15,50 chrome
3392738 root 19 -1 32.9g 58028 0 S 9.2 0.1 10,40 chrome
3796437 root 20 0 0 0 0 I 8.9 0.0 1:22.44 kworker/u32:3-ext4-rsv-conversion
3511614 root 19 -1 33.0g 193728 0 S 8.3 0.3 7,40 chrome
3269936 root 19 -1 32.9g 58116 0 S 8.0 0.1 15,51 chrome
3266820 root 19 -1 32.9g 58056 0 S 7.0 0.1 16,06 chrome
3268384 root 19 -1 32.9g 57840 0 S 6.4 0.1 15,56 chrome
3392716 root 19 -1 32.9g 58340 0 S 6.4 0.1 10,44 chrome
to which I say.. YIKES!!!!!!!
What is the best way to throttle this and prevent puppeteer from being able to launch say no more than 10 instances of chrome?