GoogleChromeLabs / pptraas.com

Puppeteer as a service
https://pptraas.com
Apache License 2.0
457 stars 78 forks source link

Is there a reason that the service instantiates a browser each request? #41

Open michaelgmiller opened 6 years ago

michaelgmiller commented 6 years ago

I'm building a service modeled after pptraas. We're doing some performance/load testing, and it seems that lack of caching is a big issue. Is there a reason that y'all don't re-use the browser? Wondering if there are any gotchas / threading issues with re-using the browser. Certainly seems like a big performance advantage to do so!

ebidel commented 6 years ago

Launching a new instance is more costly, but it keeps things cleaner. Eventually, I've seen Chrome run out of memory and crash the server. In other cases you really want a clean profile for every request.

However, if you're building something production worthy and need to do performance tuning, I'd definitely look into launching the browser once and reusing the instance. Puppeeteer added the ability to create new browsing contexts since we built this demo site. That would be the way to go if you need clean sessions per request, but want to reuse the browser. We should move pptraas.com to using that model.

For reusing an instance, check out https://github.com/ebidel/try-puppeteer/blob/master/backend/server.js#L226. That server shows code paths for how to reconnect to the running browser using puppeteer.connecft