Matti Paksula, Supervisor Cloud Oy. First published in Finnish in the testing magazine Laatu ja testaus, issue 2/2018 (PDF, in Finnish). Translated from Finnish; the examples are from 2018.
A load test for a web service tries to find out whether the service can handle the traffic from the number of users it is expected to have. Load testing usually becomes urgent right before a launch, a few weeks before if you are lucky. At that point the developers are busy with the famous last 20 percent that takes 80 percent of the time, so the work may even be bought from a company that specialises in load testing. Specialised or not, the testing is often done incompletely or wrong.
Bombs away
Let’s start with the simpler way to load test, which I’ll call bombing here. Bombing finds out how many requests per second a web server can serve successfully. It is usually done with a well-known tool such as JMeter or Gatling, or with a SaaS service such as BlazeMeter or Loader.io. A few URLs that are expected to get the most traffic are picked from the service, for example the REST APIs from which browsers or other services fetch data.
Besides whether the requests succeed, bombing follows things like the average time it takes requests to complete and how much that time varies. The types of responses are followed too, such as how many requests are dropped because of a timeout or another error. The tools offer dashboards where the figures are easy to follow as averages, percentiles and even graphs.
Because bombing is relatively lightweight, you can probably even find the upper limit where response times get too long or there are too many errors. The developers fix the bottleneck when they get to it, and the test can be run again to get to the next bottleneck. This kind of simple testing often doesn’t even need an outside company; developers or testers can do it themselves. It’s good that testing and fixing happens at all, but unfortunately bombing is only seemingly effective at finding the real bottlenecks.
The internet has changed
When Apache JMeter was released in 1998, the internet looked very different. Pages were often physical .html files on the web server’s hard disk, and JavaScript was used mainly to make an animated GIF horse follow the user’s cursor. Twenty years later we talk about web services instead of web pages. They are built by teams that are even split into backend and frontend developers. The site the user sees is put together dynamically in the browser, often as the result of dozens of requests. On top of that, services link to large numbers of images, style sheets and outside scripts, for example for analytics. At the time of writing, loading the front page of www.hs.fi, Finland’s largest newspaper, makes about 200 requests.
Many of these requests are made asynchronously by JavaScript. For JMeter or a similar low-level tool to account for them, it would have to run the service’s JavaScript the way the user’s browser does. In other words, for bombing to show the real bottlenecks, all 200 URLs would have to be added to JMeter. And the tool would have to make the requests in the same waterfall order as the user’s browser (for hs.fi, in suitable bursts over about three seconds).
At this point I often hear an argument that goes like this: “Surely we don’t need to load the images, because they come from an [expensive] content delivery network (CDN) and are not directly within this service’s reach.” For some reason, when we test a web service’s performance, we often place ourselves in the service’s data centre and forget that a page’s load time is a whole, and the user, rightly, couldn’t care less how fancy the CDN serving the images is. As testers we must test the situation end to end, from the user’s side, taking into account other providers’ delays and the total network traffic all the images create. Because developers are in a hurry, the images’ CDN delivery may also be switched off by accident. And it’s worth looking at the amount of traffic from the point of view of a 3G connection on a summer cottage jetty, too.
Record it once and can it
A more advanced way to test is to install an add-on in the tester’s browser (or use a proxy) that records all the requests exactly as the browser makes them. A recording gives a much better load profile, and running it with, say, JMeter gives much better visibility into the real bottlenecks. But it’s still not perfect. A recording gives us a series of very static requests that are run one after another, and later the tool’s dashboard shows us that some of them didn’t succeed (if we see it). People may try to improve this by editing the recording, adding random pauses between requests by hand and parameterising them, which makes the recording a little more dynamic and its load profile closer to reality.
The central problem with a recording, though, is that it was made on one computer at one moment. Web services are complex systems where even hundreds of microservices make up one service, so the recording is inevitably out of date before the tester has had time to add the pauses by hand. Even when best practices such as a code freeze (the service must not be changed during testing) are followed, this way of testing is very expensive because of all the manual work, and still incomplete.
UI testing to the rescue
Let’s step outside the testing world’s tools for a moment and look at what software development does. Developers (in an ideal world) support their work with different kinds of tests: fast unit tests for single classes or functions (hundreds of tests a second) and UI tests that check the web service with an automated browser. The de facto name in UI testing has been the Java-based Selenium and its derivatives, such as the Finnish Robot Framework and Capybara. UI testing is functional testing: a browser starts and goes through the chosen path (log in, click products, choose the first product …) as fast as the local copy of the service on the developer’s machine allows. The test itself is written as some kind of program that commands each action one at a time (click image x, choose the third item in the list).
If we compare UI testing with request recordings, we notice that by simply adding natural pauses to UI tests, we get a test that loads all the images, runs all the scripts, and doesn’t move on (make the next requests) if an error happens in any layer or something takes too long. So by using UI tests “wrong”, we can replay users’ paths as they really are. A load test is then simply a matter of raising the number of simultaneous browsers towards the number of users you want. The essential difference of this method is that instead of average load times and percentiles, we can finally answer the question “how many real simultaneous users could the service serve with acceptable load times” with one clear, unambiguous number.
This way of doing things wrong is what my startup, Supervisor Cloud, is built on. We have piloted this simple idea with several well-known customers with good results. The best moment in the pilots has been when we were told that “JMeter has already found the worst bottlenecks”, and then the service melted after a few dozen browsers, which surprised everyone by doing all the small things a real person would do.
Sources
- Apache JMeter: jmeter.apache.org
- Gatling: gatling.io
- BlazeMeter: blazemeter.com
- Loader.io: loader.io
- Robot Framework: robotframework.org
- Capybara: github.com/teamcapybara/capybara
- Selenium: selenium.dev
Editor’s note: the same idea today
Supervisor’s load tests still work this way: real browsers load the whole page, run its JavaScript and move through the site as a customer would. The result is one number: how many users the site handled. In the ticket shop case, one of the bottlenecks was an icon library that slowed pages down under load, and a request-level test would never have loaded it. Today an AI agent can also start the test, read the result and the server’s logs, and propose a fix. Read more about load testing with real browsers or how to load test a website before a traffic peak.