If you are wanting to ensure that your site can handle 100 concurrent users, then you will probably want to design a test where you ramp up to 100 concurrent VUs over a period of time, and then maintain the load at that level for another period of time. This would be achieved using the Ramping VUs executor.
As this type of executor option is quite common in load testing, there’s a shortcut to define it which doesn’t involve creating a full-blown scenario. To utilize the shortcut, all you need to do is specify stages within your options
.
Here’s an example:
export const options = {
stages = [
{ duration: '10m', target: 100 },
{ duration: '10m', target: 100 },
],
}
With the above, your test would ramp-up to 100 VUs from 0 over 10min, and then keep the load at 100 for a further 10 minutes.
Important to note is that concurrent VUs don’t necessarily translate directly to concurrent real users. A VU is executing code and will do so as fast as it can, whereas a real user would navigate, spend some time absorbing what’s on the page, and then a while later navigate to another page, and so on.
That is why adding sleep
statements is important: they allow you to introduce “think time” that slows down the speed of a VU so that it more closely mimics the actions of a real user. These sleep
statements are typically added between requests or between group
functions, in situations where there are multiple HTTP requests that take place as a result of a single user-initiated action.
Take a look at this repo if you want to see an example set of scripts that employ the above:
You’ll note that the sleep
statements in main.js also randomly select a duration from within a range (2-5sec). This further increases the realism of the test (some users will naturally navigate around faster than others). What the range should be will completely depend on how long you yourself think real users would spend on each page of your site.
I’ll also point out that the definition of “concurrent users” is not particularly well-defined. If I remember correctly, Google Analytics will consider a user to still be “active” until it sees 2min of inactivity. Worth bearing in mind!
Hope that helps.