Load Testing Strapi CMS

Strapi is a leading opensource headless CMS, and actually powers the backend to the LoadForge blog. We recently decided to run a load test on our Strapi installation, and have documented how below.

Add 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. Once you add your Host you need to validate it. You can do this by either writing a file to the Strapi public web folder, or with a DNS record which is typically the easiest.

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 LoadForge blogs is "lfBlogs" and so we put in the same query our blog frontend uses to test that we get the reply we expect:

{
  lfBlogs {
    id
    title
    excerpt
    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 lf_blogs(self):
        query = '''
            {
              lfBlogs {
                id
                title
                excerpt
                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.

Ready to run that test?
Start your first test within minutes.