TBB Polska's Web Development Blog

Will My Site Survive? How to Run a Basic Load Test

  • Can my website survive multiple people visiting it?
  • How many people can visit my website at the same time?
  • Is there a particular page, or series of pages, that is causing my server to become unresponsive, or even crash?

These are a few questions that load testing - which involves using fake visitors to test your website's performance - can answer

Note: this is an absolutely basic guide to load testing, and this is a potentially huge topic. For instance, having multiple, independent servers generating the test visitors would be a huge plus, and if you already have access logs, you could use these to simulate how users actually interact with your site.

Let's get started. We're going to use JMeter, and you can download the latest version here.

I have two warnings you need to be aware of:

  • Do not run load tests against your live website. Just. Don't.
  • Also do not run load tests against servers that you cannot manually restart.

Both of the above learned through bitter and painful experience over the last 15 years

For your first step, you need to decide "what do I need to test"? Whilst throwing huge numbers of visitors randomly at your website might prove that it can survive such things, you will get much, much more out of load testing if you have a specific plan or idea of what needs to be tested.

In this example, I've made a couple of changse to TBB Polska's website, and want to see if there are any hidden surprises waiting to jump out. I'm going throw visitors at a few pages on a test installation of the site, and record what happens.

Loading JMeter, it shows an empty test plan:

First, I'm going to set up the default settings for my test. Do this by right-clicking on Test Plan, selecting Add -> Config Element -> HTTP Request Defaults:

Fill in the server name. For this test, it's also really important to check the Retrieve All Embedded Resources option. This tells JMeter to download images, CSS, Javascript and all other resources in each page:

When a normal - real! - user browses your website, this is how their browser will behave, and consequently it will give us a better idea of how your server's performing.

Next, we need to tell JMeter how many users to simulate. Do this by selecting Add -> Threads (Users) -> Thread Group:

Fill in the three fields below. Think of threads as unique users, the loop count as how many times each user visits your website:

10 threads might seem low, but it's fine for testing the absolute basics. If you're feeling adventurous, feel free to increase this to 100 threads:

Now we're getting to the specifics, let's start adding pages for JMeter to test! Right-clicking on our thread group, selecting Add -> Sampler -> HTTP Request:

Enter a name that you can identify the page by, and then the path to the page. For the homepage, we can use a lone forward slash:

I'm going to add a few more pages to my test. The basic pattern is the same, a useful name followed by the path on the server:

The final piece remaining is to tell JMeter where to put the results. We'll use Graph Results and Summary Report. We can add these by right clicking on the thread group, clicking on Add -> Listener -> Graph Results, and Add -> Listener -> Summary Report:

Now the fun begins! Click the start button to begin the test:

As the test runs, the Graph Results and Summary Report will update with the results:

The test is being run on an underpowered virtual machine running on my laptop, but even with these slow results, we can see that the Contact Us page is struggling. More happily, we can see that no errors have been reported.

During the test, I have also been on the server, watching for any warning signs that the server is struggling. Not seeing any problems and checking the application error logs, I'm confident that everything will be alright, once I've taken care of the Contact Us page's slowness.

So there's a really basic test for you. I hope this has given you enough with which to get up and running. If you have any questions, ask away! :-)


comments powered by Disqus