question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Memory heap : best use of page "newPage" and urls "goto"

See original GitHub issue

Tell us about your environment:

  • Puppeteer version: puppeteer@1.11.0
  • Platform / OS version: Centos 7
  • URLs (if applicable): 500000 urls crawled one by one
  • Node.js version: v10.14.2

I’m using puppeteer to crawl web pages. Should I create only one page to go to all urls (url by url)? or should I create a new page for each url and close it once the page is loaded (always url by url, one after the other).

The problem with the first solution (creating only one page) is the high memory use. The memory used by the page is constantly increasing. This error is : FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory This occurs when 1.5 GB of memory is reached.

The problem with the second solution (creation one page for each url) could be the creation/closing of 500000 pages (one page per url). Is it optimized,? Is it the the best practice?

Thanks

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mikeyooncommented, May 28, 2021

It’s been over two years, but I’ve run into a similar (same?) issue and found a workaround that isn’t too tough to implement. The leak seems to happen in the Browser object or something related, so disconnecting and reconnecting it worked pretty well in my case. After reconnecting, you will need to reassign your Page references.

const browser = await puppeteer.launch(/* options */);
const endpoint = browser.wsEndpoint();

while (true) {
  // do your page load, etc
  browser.disconnect();
  browser = await puppeteer.connect({
    browserWSEndpoint: endpoint,
    defaultViewport: null,
  });
  page = (await browser.pages())[0];
}

With this, I could reload the url using the same page indefinitely, whereas before it would run out of memory in about 2 days.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Memory heap : best use of page "newPage" and urls "goto"
The problem with the first solution (creating only one page) is the high memory use. The memory used by the page is constantly...
Read more >
node.js - Managing puppeteer for memory and performance
The library puppteer-cluster (disclaimer: I'm the author) creates a pool of browsers or pages for you. It takes care of the creation, error ......
Read more >
How does the paging concept work with heap and stack ...
When a process allocates memory, the corresponding page-table entries are allocated, and initialised to point to the zero page (except on ...
Read more >
Puppeteer documentation - DevDocs
Puppeteer 7.1.0 API documentation with instant search, offline support, keyboard shortcuts, mobile version, and more.
Read more >
Web Performance Recipes With Puppeteer - Addy Osmani
This guide has recipes for automating Web Performance measurement with Puppeteer.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found