Skip to content
This repository has been archived by the owner on Oct 19, 2023. It is now read-only.

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

Open
michaelgmiller opened this issue Sep 1, 2018 · 1 comment

Comments

@michaelgmiller
Copy link

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!

@michaelgmiller michaelgmiller changed the title Is there a reason that the service instantiates a browser each run? Is there a reason that the service instantiates a browser each request? Sep 1, 2018
@ebidel
Copy link
Contributor

ebidel commented Sep 1, 2018

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants