Stress testing - Headless Chrome is the future!

May 17, 2017 09:05

Recently, I've been wondering how developers stress test web systems after needing to stress test a system myself. My requirements, I thought, were not that unique:

  • Be able to record "user stories(?)" so the system can be tested under realistic conditions
  • Be able to be scaled up to a specific amount of "users"
  • Use a REAL BROWSER so javascript can be tested
  • Report page load times, which can be corroborated to other analytics such as server render time

It wasn't simple, and I've ended up rolling my own using the Google Chrome's Headless mode

Firstly, there are options out there. A few honourable mentions:

Artillery - Super close to what I needed, but couldn't find a way of using Selenium for multiple browser testing. If I was starting out now, I would use this option - and find a way of doing it.

Load Impact - Looks to do exactly what I need, but completely out of my price range.

In the end, I created a basic system that:

  • Reads a random user story from a folder. The user stories are recorded Selenium tests that were recorded with the Selenium IDE.
  • Spin up a new process to run the Selenium test
  • All this is ran inside a Python script using a ThreadPool

Untitled

On the biggest DigitalOcean droplet I have access to (the one in blue above) this can spawn around 800 concurrent tests, without any optimising, before the server starts to chug.

The reason this works well, is that Headless Chrome is pretty amazing. The footprint of the browser instance is tiny, but still provides really great features. From reading articles and development forums, its only going to get better.

I did however find the process to install it a pain. Iif you are having problems installing it on Ubuntu, here are the commands I used to install. Please excuse the -y on the commands - this is part of a bash file I use to setup the server when I need to spin the system up >

#! /bin/bash

# Python things
apt-get install python-pip -y
pip install selenium

# Chrome
apt-get install libxss1 libappindicator1 libindicator7 -y
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome*.deb
apt-get install -f -y

# Chrome Unstable!
sh -c 'echo "deb [arch=amd64] https://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
apt-get update 
apt-get install apt-transport-https -y
apt-get install google-chrome-unstable -y

# Chromedriver
apt-get install unzip -y
wget -N http://chromedriver.storage.googleapis.com/2.29/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
chmod +x chromedriver
sudo mv -f chromedriver /usr/local/share/chromedriver
sudo ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver
sudo ln -s /usr/local/share/chromedriver /usr/bin/chromedriver