Guides

WordPress Load Testing

Load testing your WordPress Blog or CMS is made extremely easy by LoadForge. We are going to be showing how to simulate a real set of users, browsing through your latest blog posts at random.

Load testing (aka stress testing) your WordPress Blog or CMS is made extremely easy by LoadForge, and you can test it with a free account today. We are going to be showing how to simulate a real set of users, browsing through your latest blog posts at random.

Adding your Host

adding-host.png

The first step on LoadForge is adding your Host. We're going to be load testing https://mmo-population.com/blog/ - the Blog for MMO Populations. The first step is going to Hosts on LoadForge and adding "mmo-population.com" as a host and verifying it.

Making a Test Plan

Next up we add our Test. When you head to Tests you will select your Host, and set several key variables:

  • Virtual Users - the number of total users to simulate browsing your blog
  • Rate - the growth rate per second that users will scale
  • Workers - the number of servers to launch to run your test, typically 1 per 10,000-20,000 virtual users.

test-sizing.png

Then the main part is your locust file. You can run a very simple basic test and just test your index page (e.g. / or /blog). Or, you can use an advanced test like the one we will give you below to crawl the site like a real user.

There are 3 main components of our test description:

  • At start, fetch /blog/ and look for any anchor tags that match ".blog-list-post h2 a" - this is us finding all the blog posts on the index page. You can adjust this.
  • Then start crawling static content, like images and logos
  • Crawl all the blog posts we found at random (like a user), and then index page in equal shares.

Below is your test:

from locust import HttpUser, task, between
from pyquery import PyQuery
import random

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

    def index_page(self):
        r = self.client.get("/blog/")
        pq = PyQuery(r.content)

        link_elements = pq(".blog-list-post h2 a")
        self.blog_urls = []

        for l in link_elements:
          if "href" in l.attrib:
            self.blog_urls.append(l.attrib["href"])

    def on_start(self):
        self.index_page()

    @task(1)
    def static_content(self):
        # images
        self.client.get("/img/logo/logo.png")
        self.client.get("/img/images/cta_img.png")
        self.client.get("/img/logo/logo.png")
        self.client.get("/img/images/footer_fire.png")
        # styles
        self.client.get("/css/compiled.css")
        # scripts
        self.client.get("/js/compiled.js")

    @task(3)
    def blog_post(self):
        url = random.choice(self.blog_urls)
        r = self.client.get(url)


    @task(3)
    def home_page(self):
        self.client.get("/blog/")

Note: you should replace the static content section with your static urls (or use the wizard to generate them). Also make sure your CSS selector for blog links is correct, and your url (e.g. / vs /blog/)

Running the Test

Now you can start your load test. Once you begin you will see a live status output of the test, like the below:

running-test.png

Once the test completes you will be given a full report on the performance of your blog. You can also run the test again with more users, different settings, etc. We recommend starting with a smaller number of users and scaling up as you see you are not getting failures.

Below are a few sample images of the reports for our test:

mmo-report.png

graphs.png

Final Words

Remember that if you use / instead of /blog/ you should change that in the test. You may also need to change the link_elements = pq(".blog-list-post h2 a") line to match your URLs.

While you are at it, make sure you read our guides on high performance Nginx and PHP-FPM:

Interpreting the results of your test are as important as running the test, if not more. Continue this on our reading load test results guide.

Ready to run your test?
Launch your locust test at scale.