Scaling for success: load testing your app for Black Friday – part 3

Effective load testing replicates real-world scenarios, putting your application through its paces with simulated traffic patterns that mimic Black Friday. This proactive approach prepares your system for high demand and builds confidence in its reliability and performance under pressure.

By Thomas di Luccio, on Aug 28, 2024

In the first two installments of this series, we laid the groundwork for successful load tests by creating a perfect carbon copy of our production application, setting up a locust instance, and bootstrapping our first load test file. It’s now time to enrich our tests so the generated traffic is as realistic as possible to what’s happening during Black Friday.

A good practice is to check the list of the most critical transactions in Blackfire’s monitoring dashboard. This provides a convenient way to determine the endpoints that must be included in your load tests. Alongside the critical user journeys leading a user from your homepage to a valid order, this increases your chances of securing the parts of your application that are likely to be under the highest pressure.

A few more tweaks, and you’ll have a solid test file at your disposal. It’s finally time to click the Start call-to-action, and get started for your first load test. Locust provides a convenient dashboard to witness the load testing unfurl before our eyes.

Keeping your eyes on your objectives

We previously mentioned that load testing serves two purposes: discovering throttling parts of your application and ensuring it is correctly scaled. Now that we designed load tests let’s see how to make the most of them and their results.

Exploring the monitoring and continuous profiling data for the timeframes of the test provides in-depth information about the most impactful spans and transactions. Each test can help you identify improvement opportunities.

The number of errors lets you understand the real limit in terms of traffic and concurrent users your project can currently sustain. Repeating load tests for every improvement you make can ensure you are going in the right direction on this journey toward growth and supporting way more significant traffic.

You could even consider further lowering the complexity of running such tests by enabling their automation. While Locust provides a convenient UI, it can run entirely on the command line by passing the --headless option. Other options let you control the maximum number of concurrent users, spawn rate, and even time limit to perform this test.

More importantly, Locust lets you control the exit code of the load-testing process. This means you can design your tests in a way that allows you to receive a yes-or-no answer to your traffic-related questions. Can our project serve X concurrent users with a satisfactory user experience?

In this snippet, we return a non-zero exit code  if any of the following conditions are met:

  • More than 1% of the requests failed
  • The average response time is longer than 200 ms
  • The 95th percentile for response time is larger than 800 ms
import logging
from locust import events

@events.quitting.add_listener
def _(environment, **kw):
	if environment.stats.total.fail_ratio > 0.01:
    	logging.error("Test failed due to failure ratio > 1%")
    	environment.process_exit_code = 1
	elif environment.stats.total.avg_response_time > 200:
    	logging.error("Test failed due to average response time ratio > 200 ms")
    	environment.process_exit_code = 1
	elif environment.stats.total.get_response_time_percentile(0.95) > 800:
    	logging.error("Test failed due to 95th percentile response time > 800 ms")
    	environment.process_exit_code = 1
	else:
    	environment.process_exit_code = 0

Such an automated process could even find its place in your Github actions and deployment workflows. While you might want to run those resource-intensive tests sparingly, lowering the complexity of this process by crafting an easily reusable tool will be a significant addition to your performance optimization apparatus.

Having such a tool at your disposal puts you in a much better position to grow and benefit from all the opportunities that come with those intense events. You can confidently ride the traffic wave without fear of being crushed by it.

If not, you would keep gambling and placing bets on your success without insurance on how things could turn out. You would have one year to blindside hope for things to improve next time.

If you don’t currently have a Blackfire subscription, now is a good time to get one. With it, you can start regaining control of your application’s performance and enabling its growth. 

To better observability and beyond


The “Scaling for success: load testing your app for Black Friday” series:

Thomas di Luccio

Thomas is a Developer Relations Engineer at Platform.sh for Blackfire.io. He likes nothing more than understanding the users' needs and helping them find practical and empowering solutions. He’ll support you as a day-to-day user.