Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added option to manually request browser restart #310

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ramiloif
Copy link

@ramiloif ramiloif commented Jul 3, 2020

Option to request Cluster to restart the browser manually.
Motivation: sometimes when Google Chrome is running too long the RAM usage is increases.
Restart chrome from time to time (for example every 1k jobs) may be handy.
I added an implementation for that.
Restart may be handy for other reasons too. (Update some data from data dir ...)
Implementation:
Added public abstract requestRestart(): void; to ConcurrencyImplementation
Relevant mostly to to SingleBrowserImplementation
But as SingleBrowserImplementation extends ConcurrencyImplementation I couldn't find a way not to put it in the interface.

I tested It against my use case and it worked.

@tenkuken
Copy link

How to install and using this ?

@ramiloif
Copy link
Author

ramiloif commented Jul 17, 2020

Hi @tenkuken
you can install it from my fork,
using: ( install pupeteer-cluster from my fork)
npm install git+https://github.com/ramiloif/puppeteer-cluster.git

Usage create the cluster with CONCURRENCY_PAGE or CONCURRENCY_CONTEXT
For example:
const cluster = await Cluster.launch({
concurrency: Cluster.CONCURRENCY_CONTEXT,
maxConcurrency: 2,
});

Then when you want to schedule browser restart just call
cluster. requestRestart ();

Please update here how is that working for you .

@tenkuken
Copy link

Unfortunately, i'm using CONCURRENCY_BROWSER for perbrowserOptions.
As i can see, it won't work.

Thank you for update.

@ramiloif
Copy link
Author

But if you’re using CONCURRENCY_BROWSER why do you need this restart?
Isn’t it automatically starts new browser for each task?

@tenkuken
Copy link

I'm sorry, It is automatically starts new browser for each task.
so CONCURRENCY_BROWSER doesn't need this restart feature.
It's my mistake.

@StringKe
Copy link

StringKe commented Jun 30, 2021

I try to execute requestRestart a certain number of times in doWork(doWork function in cluster.ts), but it doesn’t seem to work.

 private async doWork() {
    const doneJob = this.allTargetCount - this.jobQueue.size() - this.workersBusy.length;
    if (doneJob > 0 && doneJob % this.options.queueLimit === 0) {
      if (this.options.queueLimitRestart) {
        // this.requestRestart();
        this.requestRestart();
        // await Promise.all(this.workers.map(async (worker) => await worker.browser.repair()));
        Logger.log('max loop restart cluster', 'Puppeteer Cluster');
      } else {
        throw new Error('Queue limit reached');
      }
    }

...

TheNimbleSapMan added a commit to Nimbleway/puppeteer-cluster that referenced this pull request Apr 11, 2022
TheNimbleSapMan added a commit to Nimbleway/puppeteer-cluster that referenced this pull request Apr 11, 2022
Added pull request thomasdondorf#310 from puppeteer-cluster
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants