I have a node/express server where we use Puppeteer to open a website, do certain manipulations, and then take screenshots.The performance of this whole process gets degraded when I run it on a test server. There is no load on the test server we are using it delicately to test this. The CPU and memory are also well in control
The only difference I see is on the server puppeteer is running in headless mode. I have looked at all the issues around this on the Puppeteer GitHub issues page but none of the solutions work.
Example: The below code on my local m2 Mac takes around 2 seconds but on the server, it takes almost 10 seconds. I can't understand the issue since the CPU cores provided are 4 and are very underutilized ( below 1 ) and the memory usage is also 1/4th of the limit.
async function refreshHeatmap(page: Page, heatmapBottomBar: Frame | null | undefined) {
// refreshing heatmap
await page.evaluate(() => {
return (window.top.dataLoaded = false);
});
await heatmapBottomBar?.evaluate(() => {
window.application.refreshCanvas();
});
await waitForRefresh(page);
}
async function waitForRefresh(page: Page) {
await page.waitForFunction(() => {
return window.top.dataLoaded === true;
}, {});
}
Can anyone please help me out here? What could be the problem here?
Server Environment Details: Debian Os 10 with memory of 6 GB and 4 CPU cores. The whole thing is containerized with docker and running via Kubernetes. The node version being used is 16
Expectations was the example code would not be 5x slow on server if cpu and memory usage is not an issue.