Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Chrome with `--headless` switch to measure user page load times

I'm trying to improve the performances of my web server and would like to get an accurate measure on how long it takes the user to load the page. The way I imagined this would be to simulate concurrent requests from users and track how page load times change as I fine-tune various settings to get optimal results.

I'd like to use the latest snapshot of Chromium with the --headless switch to measure how long it would take the user to load the page, but since this is a relatively new feature and I'm not familar with all the possible switches, I'd appreciate if someone can share what they would run to get accurate results.

The only limitation I have is that I can't inject scripts or modify the response content in some other way that would be helpful for such a test.

like image 594
Filip Dupanović Avatar asked Dec 27 '16 02:12

Filip Dupanović


People also ask

How do I use Chrome headless?

To visit a website in Chrome Headless, all you have to do is add the URL after the headless flag in the command line. Again, you'll see the Canary icon jump up and disappear in the Doc. But that's all you'll see.

What does headless chrome mean?

Headless mode is a functionality that allows the execution of a full version of the latest Chrome browser while controlling it programmatically. It can be used on servers without dedicated graphics or display, meaning that it runs without its “head”, the Graphical User Interface (GUI).

How do I run Chrome headless in Linux?

You can run Google Chrome in headless mode simply by setting the headless property of the chromeOptions object to True. Or, you can use the add_argument() method of the chromeOptions object to add the –headless command-line argument to run Google Chrome in headless mode using the Selenium Chrome web driver.


1 Answers

This seems to be ok-ish. Taking a screenshot shows the page seems to be loaded and getting similar results between the first and subsequent requests, so I'm assuming caching is indeed disabled.

time chromium \
  --headless \
  --disk-cache-dir=/dev/null \
  --disable-gpu \
  --download-whole-document \
  --deterministic-fetch \
  https://www.stackoverflow.com

Notes

  • this doesn't warm up the DNS entries on the initial request, so it'd probably be best to discard the first result
  • the --disable-gpu flag isn't necessary, but there is a reported error with the current build
  • opening up a remote debugging port could probably be useful to remove references to 3rd party sources that skew results or to have more control over what's considered a fully loaded page, say wait for some scripts to fetch additional resources, but it's a bit way over my head
like image 103
Filip Dupanović Avatar answered Sep 22 '22 12:09

Filip Dupanović