When running load tests, you may want to test different types of load. For example, you may want to stress test your web server or load test your API.

However, the most common scenario is simulating real users for when you experience a traffic spike.

Real user browsing is made up of a few key components:

  • Simulated wait times
  • Full page loads
  • User sessions

Wait Times

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

Recommended wait times:

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

You’ll notice these are 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)

This instructs LoadForge to wait a random amount between 5 and 9 seconds between actions.

Loading Static Content

A real user also loads all your static content—images, CSS, JavaScript, etc. However, browsers cache this content, meaning they load it less frequently as users continue browsing.

You want to simulate loading static content first and then focus on dynamic content. Here’s an example of a test script that simulates a real user visiting 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("/")
        # Load CSS
        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")
        # Load JavaScript
        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")

    # Simulate visiting different pages
    @task(1)
    def visit_pages(self):
        urls = [
            "", "/", "/products/", "/we-care/", "/corporate/", "/products",
            "/1000-screenshots-per-month-for-free/", "/author/gbv/",
            "/loadforge-launches-white-labelling-for-reports/", "/tag/loadforge/",
            "/sponsoring-laravel-io/", "/tag/news/"
        ]
        for url in urls:
            self.client.get(url)

In this script:

  • The index_page task loads the homepage along with its static assets.
  • The visit_pages task simulates navigating through various pages of the site.
  • The wait_time ensures that user behavior remains realistic, with a pause between actions.

Next Steps

  • Use the Wizard to create your own test.
  • Copy test examples from the documentation under the Example Tests and Snippets category.
  • Customize your tests further based on your website’s user behavior patterns.

Simulating real user behavior helps you create realistic load tests, ensuring that your site remains stable under peak traffic conditions.