BLOG // May 2, 2021

Load Testing my Strapi CMS Backend with LoadForge

Strapi is a leading opensource headless CMS, and actually powers the backend to this blog. LoadForge is a developer-focused load testing / stress testing platform.

I recently decided to run a load test on my Strapi API installation, and have documented how below.

Add the host

The first step to any new test on LoadForge is to add your Host. Mine 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.

Tip: if you use a DNS record at the TLD level you can automatically validate any subdomains you add to LoadForge - super handy.

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 mine @ https://strapi.advent.dev/graphql as it's public.

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

{
  blakeyBlogs {
    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 blogs(self):
        query = '''
            {
              blakeyBlogs {
                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.

If you'd like to give it a try sign up for LoadForge and get going!

Comments

Subscribe to new articles

If you enjoy my content, consider subscribing. You will only receive new blog stories, no other email.