Guides

Strapi Load Testing

How to load test the Strapi headless CMS with LoadForge.

Strapi is a leading opensource headless CMS, and actually powers the backend for LoadForge blogs and guides (like this guide!).

This guide will help you to easily load test your Strapi installation and scale your installation. LoadForge is capable of generating up to 500,000 SSL requests per second, far more than any reasonable Strapi installation can deliver, making it ideal for understanding your capacity.

Adding the host

The first step to any new test on LoadForge is to add your Host. Ours is https://strapi.advent.dev:443 but this can often be naked Strapi running on port 1337 so make sure to specify the port. Once you add your Host you need to validate it. You can do this by writing a file to the Strapi public web folder, or with a DNS record which is typically the easiest - especially with Strapi installations.

Test Your Query

It's very easy to load test GraphQL APIs with LoadForge as we've talked about before, and Strapi is no different.

Go to your Strapi URL directly and head to /graphql, for example you can experiment with ours @ https://strapi.advent.dev/graphql as it's public.

The Collection Type for most Strapi installations is "articles" and so we put in the same query our blog frontend uses to test that we get the reply we expect:

{
  articles {
    id
    title
    slug
    body
  }
}

You can see a screenshot of this working live below.

strapi-load-test.png

Create Your Test

Now create a LoadForge test using your Host with a test config based on your query above:

from locust import HttpUser, task, between

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

    @task(1)
    def blogs(self):
        query = '''
            {
              articles {
                id
                title
                slug
                body
              }
            }
            '''

        response = self.client.post(
            "/graphql",
            name="GraphQL",            
            json={"query": query }
        )          

As you can see above, you are essentially just posting your query (and can do many different ones if needed) to the GraphQL endpoint.

Check Your Results

LoadForge will prepare a report for you after you run your test, that will look something like this:

strapi-load-test-report.png

You can also see graphs, errors (if any occurred) and more.

We recommend starting small and monitoring the CPU usage on your Strapi server. Then you can start to increase the number of virtual users LoadForge is sending as you scale it.

Ready to run your test?
LoadForge is cloud-based locust.io testing.