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.

goto is slow when loading webgl heavy page within docker

See original GitHub issue

Hi all,

I’m running puppeteer in a docker container following the guidance in the troubleshooting doc. Everything works well but I’ve noticed that the performance of loading a webgl heavy page is quite slow. In my specific case, I am loading a page which runs mapbox-gl.

To highlight the difference here are some timings of running page.goto on my macbook and then in a docker container on my macbook.

node src/index.js on my macbook:

https://www.mapbox.com/mapbox-gl-js/example/simple-map/: 3063.949ms
https://www.mapbox.com/mapbox-gl-js/example/simple-map/: 4452.650ms
https://www.mapbox.com/mapbox-gl-js/example/simple-map/: 4230.794ms
https://www.mapbox.com/mapbox-gl-js/example/simple-map/: 2490.617ms
https://www.mapbox.com/mapbox-gl-js/example/simple-map/: 2317.874ms
https://www.mapbox.com/mapbox-gl-js/example/simple-map/: 4229.287ms
https://www.mapbox.com/mapbox-gl-js/example/simple-map/: 2354.100ms
https://www.mapbox.com/mapbox-gl-js/example/simple-map/: 2327.328ms
https://www.mapbox.com/mapbox-gl-js/example/simple-map/: 2322.225ms
https://www.mapbox.com/mapbox-gl-js/example/simple-map/: 2327.917ms

docker build -t mapbox_puppeteer . && docker run mapbox_puppeteer on my macbook:

https://www.mapbox.com/mapbox-gl-js/example/simple-map/: 6463.545ms
https://www.mapbox.com/mapbox-gl-js/example/simple-map/: 5926.895ms
https://www.mapbox.com/mapbox-gl-js/example/simple-map/: 5821.330ms
https://www.mapbox.com/mapbox-gl-js/example/simple-map/: 4994.213ms
https://www.mapbox.com/mapbox-gl-js/example/simple-map/: 5873.299ms
https://www.mapbox.com/mapbox-gl-js/example/simple-map/: 4991.777ms
https://www.mapbox.com/mapbox-gl-js/example/simple-map/: 4994.862ms
https://www.mapbox.com/mapbox-gl-js/example/simple-map/: 5883.109ms
https://www.mapbox.com/mapbox-gl-js/example/simple-map/: 4992.620ms
https://www.mapbox.com/mapbox-gl-js/example/simple-map/: 5966.262ms

Taking a look at a trace from both scenarios shows that within docker a lot more time is spent Scripting:

Running node on my macbook: screen shot 2018-03-15 at 19 39 25

Running inside Docker on my macbook: screen shot 2018-03-15 at 19 39 33

Perhaps this is an issue with the chrome distribution thats installed in docker? Or maybe this is an issue with docker itself not fully leveraging my GPU? FWIW I also have access to a kubernetes cluster running nodes with 1x NVIDIA Tesla K80… but the performance issue remains.

Looking for some guidance here.

For reference, here is my code:

src/index.js

const puppeteer = require('puppeteer');
const PUPPETEER_EXECUTABLE_PATH = process.env.PUPPETEER_EXECUTABLE_PATH;

const PUPPETEER_BASE_ARGS = {
  headless: false, // headless doesn't support webGL
  args: [
    '--headless',
    '--hide-scrollbars',
    '--mute-audio',
    '--no-sandbox',
    '--disable-dev-shm-usage', // https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md#tips
  ],
};


(async () => {
  const browser = await puppeteer.launch({
    executablePath: PUPPETEER_EXECUTABLE_PATH,
    ...PUPPETEER_BASE_ARGS,
  });
  const url = 'https://www.mapbox.com/mapbox-gl-js/example/simple-map/';
  for (let i = 0; i < 10; i++) {
    const page = await browser.newPage();
    try {
      console.time(url);
      await page.goto(url, {
        timeout: 20000,
        waitUntil: 'networkidle0',
      });
      console.timeEnd(url);
    } finally {
      await page.close();
    }
  }

  // create a trace
  // const page = await browser.newPage();
  // await page.tracing.start({ path: 'trace.json' });
  // await page.goto(url, {
  //   timeout: 20000,
  //   waitUntil: 'networkidle0',
  // });
  // await page.tracing.stop();

  await browser.close();
})();

Dockerfile

FROM node:9-slim

# For more info on this Dockerfile see:
# https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md

# See https://crbug.com/795759
RUN apt-get update && apt-get install -yq libgconf-2-4

# Install latest chrome dev package and fonts to support major charsets (Chinese, Japanese, Arabic, Hebrew, Thai and a few others)
# Note: this installs the necessary libs to make the bundled version of Chromium that Puppeteer
# installs, work.
RUN apt-get update && apt-get install -y wget --no-install-recommends \
    && wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
    && sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
    && apt-get update \
    && apt-get install -y google-chrome-unstable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst ttf-freefont \
      --no-install-recommends \
    && rm -rf /var/lib/apt/lists/* \
    && apt-get purge --auto-remove -y curl \
    && rm -rf /src/*.deb

# It's a good idea to use dumb-init to help prevent zombie chrome processes.
ADD https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64 /usr/local/bin/dumb-init
RUN chmod +x /usr/local/bin/dumb-init

RUN mkdir -p /app/

# Add user so we don't need --no-sandbox.
RUN groupadd -r pptruser && useradd -r -g pptruser -G audio,video pptruser \
    && mkdir -p /home/pptruser/Downloads \
    && chown -R pptruser:pptruser /home/pptruser \
    && chown -R pptruser:pptruser /app

# force docker to cachebust all app specific commands
ARG CACHEBUST=1
COPY . /app/
WORKDIR app

# skip chromium download when installing puppeteer
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true
ENV PUPPETEER_EXECUTABLE_PATH google-chrome-unstable

# cachebust when doing yarn install so we can update dependencies in package.json
RUN yarn install

# Run everything after as non-privileged user.
USER pptruser

EXPOSE 8080

ENTRYPOINT ["dumb-init", "--"]
CMD ["node", "src/index.js"]

Thanks!

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
ebidelcommented, Mar 21, 2018

I’m not sure the host GPU is available inside the container. A little googling suggests you need to set this up yourself:

https://medium.com/@ceshine/docker-nvidia-gpu-nvidia-docker-808b23e1657 https://github.com/SeleniumHQ/docker-selenium/issues/340#issuecomment-279800757

0reactions
reyaprcommented, Jul 26, 2018

same to me, i use puppeteer with jest, i run in my locally it pass in 17s for 1 login test, but in docker it failed and gave error

Timeout - Async callback was not invoked within the 30000ms timeout specified by jest.setTimeout.

with 63s times

Read more comments on GitHub >

github_iconTop Results From Across the Web

goto is slow when loading webgl heavy page within docker
Hi all, I'm running puppeteer in a docker container following the guidance in the troubleshooting doc. Everything works well but I've ...
Read more >
WebGL slow loading? - Unity Forum
After uploading the WebGL project to an Azure App service website the WebGL player usually takes about 20 seconds to load a simple...
Read more >
Enabling Hardware Acceleration for Headless Chromium with ...
It provides instructions for how to enable GPU hardware acceleration for slow Playwright tests in headless mode. However, no matter what I do ......
Read more >
7 Common Mistakes in Professional Scraping - incolumitas.com
In this blog post, I am talking about my several year long experience with web scraping and common mistakes I made along the...
Read more >
Discussion of Stop Using React - DEV Community ‍ ‍
I believe the main issue is with the way we write and run code on the web. For example, having just one programming...
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