Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Puppeteer slow down after a few hours

I'm having some issues with my node app and it slowing down after a few hours on my EC2 server.

My app uses puppeteer, bull and mongodb, I have a bull queue which my app reads to process, once the job is complete it then writes the results to mongodb, so this process runs until the queue is complete (7000 jobs). When I start the app puppeteer takes around 5-10 seconds to return the results, the longer the process runs the slower it gets, after about 2-3 hours it starts taking 30-50 seconds to run a job. If I stop and start the process the jobs return back to the initial 5-10 seconds speed for 10 minutes until returning back to 30-50 seconds.

I've checked memory, it doesn't seem to be using excessive memory it stays around the same level the whole time. I've also checked the CPU and I don't think its running into any issues with that either.

Any ideas on what else could be causing the slot downs? I have noticed when the app starts the nodejs loop delay is 0.5ms after a few hours its around the 1-2ms range. Whats the best way to debug this?

Your help is much appreciated.

Thanks

like image 573
ElmosGotAGun Avatar asked May 28 '18 21:05

ElmosGotAGun


People also ask

How much RAM does puppeteer need?

Memory requirements Actors using Puppeteer: at least 1GB of memory. Large and complex sites like Google Maps: at least 4GB for optimal speed and concurrency.

Can puppeteer run in browser?

Puppeteer lets you automate the testing of your web applications. With it, you can run tests in the browser and then see the results in real-time on your terminal. Puppeteer uses the WebDriver protocol to connect with the browser and simulate user interaction with HTML elements or pages.

How do you remove cookies from a puppeteer?

While brand new browser sessions with both Puppeteer and Playwright will not contain any cookies by default, there might be points when it is necessary to clear them. In case you need to clear cookies, you can use page. deleteCookie(… cookies) with Puppeteer and browserContext.


1 Answers

You'll want to close and re-open the browser for every session if you don't already. This is a tricky endeavor and can be hard to manage as you'll need to know some inner-workings of puppeteer to make sure everything is "wired right". I maintain a docker image here, and the code to generate a clean instance of Chrome per-session is here. (dead link)

like image 110
browserless Avatar answered Sep 20 '22 03:09

browserless