Core concepts

Simulating real users

When running load tests you may want to test very different types of load. For example, you may want to stress test your webserver. Or possibly load test your API.

However, the most common is to simulate users for when you have a traffic spike.

Real user browsing is made up of a couple of key points:

  • Simulated wait times
  • Full page loads
  • User sessions

Wait times

Real users wait between page loads - they consume the content on the page, let animations or videos play, and so on. Because of this you need to simulate a wait time in your test and it depends on the type of site or your content.

We recommend these general wait times:

  • Slow - 15 to 60 seconds
  • Casual - 8 to 20 seconds
  • Standard - 5 to 9 seconds

You'll notice it's always a range, and LoadForge supports that. Your test will have a wait_time variable which typically looks like this:

wait_time = between(5, 9)

That instructs it to wait a random amount between 5 and 9 seconds.

Loading static content

A real user also loads all your static content - images, CSS, JS, etc. However, browsers cache this content meaning they typically load it a lot less as they continue to browse the site.

You want to simulate static content and then a lot of dynamic content. As an example, here is a full test script that simulates a real user hitting a blog:

from locust import HttpUser, task, between


class QuickstartUser(HttpUser):
    wait_time = between(5, 9)


    @task(3)
    def index_page(self):
        self.client.get("/")
        # images
        # styles
        self.client.get("/assets/css/app.css?v=5182f1a68d")
        self.client.get("/assets/css/home.css?v=5182f1a68d")
        self.client.get("/public/cards.min.css?v=5182f1a68d")
        # scripts
        self.client.get("/public/cards.min.js?v=5182f1a68d")
        self.client.get("/assets/js/manifest.js?v=5182f1a68d")
        self.client.get("/assets/js/vendor.js?v=5182f1a68d")
        self.client.get("/assets/js/app.js?v=5182f1a68d")


    # Separate Pages
    @task(1)
    def urls_0(self):
        self.client.get("");


    @task(1)
    def urls_1(self):
        self.client.get("/");


    @task(1)
    def urls_2(self):
        self.client.get("/products/");


    @task(1)
    def urls_3(self):
        self.client.get("/we-care/");


    @task(1)
    def urls_4(self):
        self.client.get("/corporate/");


    @task(1)
    def urls_5(self):
        self.client.get("/products");


    @task(1)
    def urls_6(self):
        self.client.get("/1000-screenshots-per-month-for-free/");


    @task(1)
    def urls_7(self):
        self.client.get("/author/gbv/");


    @task(1)
    def urls_8(self):
        self.client.get("/loadforge-launches-white-labelling-for-reports/");


    @task(1)
    def urls_9(self):
        self.client.get("/tag/loadforge/");


    @task(1)
    def urls_10(self):
        self.client.get("/sponsoring-laravel-io/");


    @task(1)
    def urls_11(self):
        self.client.get("/tag/news/");

You'll notice that index_page loads static content, but then the rest of the URLs are just the URL itself. We also have a wait_time of 5 to 9 seconds meaning that every 5 to 9 seconds our user will go to the next URL.

Next steps

Use the Wizard to create your own test, or, copy some of our test examples from the docs site under the Example tests and snippets category.

Previous
Understanding load testing