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.

Asynchronous parallel screenshotting

See original GitHub issue

Steps to reproduce

Tell us about your environment:

  • Puppeteer version: 0.13.0
  • Platform / OS version: Debian Jessie (Linux 5d08acbab1a9 4.13.12-200.fc26.x86_64) (from node:8-slim Docker image)

What steps will reproduce the problem?

I have set up very basic Express.js application which takes URL in request and returns screenshot in response. Here is the important code:

router.post('/screenshot', async function (req, res) {
  const page = await browser.newPage();
  await page.goto(req.body.url);
  const buffer = await page.screenshot();
  await page.close();
  res.set('Content-Type', 'image/png');
  res.write(buffer, 'binary');
  res.end(null, 'binary');
});

(browser is created only once).

What is the expected result? / What happens instead?

When I send multiple requests at the same time they all are completed synchronously, one after another. Node’s --trace-sync-io flag outputs a lot of info about sync I/O output too.

Question: Am I right in suggestion that it is not possible to use Puppeteer for asynchronous screenshotting with one Node process and I have to spawn multiple instances of Node?

Sorry if that should be obvious, I just want to confirm (Google did not help). Thanks in advance.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:21 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
intellixcommented, Mar 14, 2018

Also having massive issues with parallel screenshot handling and can’t seem to find a sweet spot or how to properly optimise this to perform well and not crash. I’ve currently got 12 arrays of pages to visit and screenshots to take (4 sites with desktop, mobile and tablet with different device ratios).

12 Browser with 1 page each causes server to have load of 13+ and eventually things start timing out and browsers start crashing outright 4 Browsers with 3 pages each causes load of around 6+ and again, things start to timeout. 1 Browser with 12 pages is super slow, seems to be ok, but if I only have 2 requests in, then a screenshot just stops… the whole thing just stops and there’s no error, like it just gave up and there was nothing thrown.

These are my params:

const browser = await puppeteer.launch({
  headless: true,
  args: ['--no-sandbox', '--disable-setuid-sandbox'],
});
this.page = await this.browser.newPage();
await this.page.setViewport({
  ...device.viewport,
  height: scrollHeight,
});
await this.page.screenshot({ fullPage: true });

Originally ran on an AWS t2.medium and then tried a c5.large. Nothing seems stable. I wouldn’t mind so much if it was just slower but it’s either a timeout fest or things just give up. Are there any recommendations for the flags when starting up perhaps or some extra params to setup the server with? I’ve set shared-mem to 1gb

1reaction
Oleg-Arkhipovcommented, Nov 28, 2017

@vonGameTheory thanks for your information about the fact that you made it to work, so I understood that it is something on “my” side, not Puppeteer’s. Indeed, the code is right, the problem is that I was testing by refreshing few tabs with requests in my own Chrome, and Chrome sends only one request to the same origin at the same time, haha. I then tested with ab tool and everything is right. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Asynchronous and Parallel Distributed Pose Graph Optimization
The paper presents Asynchronous Stochastic Parallel Pose Graph Optimization (ASAPP), the first asynchronous algorithm for distributed pose ...
Read more >
Cypress Asynchronous Nature - Tools QA
Asynchronous programming is a means of parallel programming whereby, a unit of work runs separately from the main application thread.
Read more >
Async method not working parallel? Simple Iteration inside ...
Parallel means two lines of code are being evaluated simultaneously (on different threads); Asynchronous means releasing the current thread ...
Read more >
Running Concurrent Requests with async/await and Promise.all
In this article I'd like to touch on async, await, and Promise.all in JavaScript. First, I'll talk about concurrency vs parallelism and why ......
Read more >
JavaScript Async/Await: Serial, Parallel and Complex Flow
Using Async/await to run asynchronous methods in series or in parallel or in complex flow in JavaScript.
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