Skip to content

Introduction to Performance Testing for Web Applications

In the world of web development, performance testing often feels like an afterthought, much like security and maintainability. We are going to do that later – a later that never appears.

However, just as maintainable code is crucial for long-term success, performance testing is essential to ensure that our web applications are robust, responsive, and ready to handle real-world demands.

As you quickly figure out, this topic looks easy, but it is not. Do not despair, there is a lot we can do without resorting to rocket science. And sometimes as few as 10 concurrent users are enough to find configuration problems.

Why performance testing matters

Imagine you launch a new feature that you developed over the last months, only to have it crash as soon as a few users click around. Performance testing helps us to prevent such scenarios by identifying potential bottlenecks and make sure that our application can handle the expected load. It is not just about speed; it is about reliability, scalability, and offering a seamless user experience.

For a long time, we got away with simply not messing things up. All we had to do was to check these 3 points:

  • Only load the data we need to display on the screen.
  • Use prepared statements so that the database can help you cache the queries.
  • Load the data in one go to prevent SELECT n+1 problems.

If we considered these 3 points, we ended up with applications that were significantly faster than the competition who made those mistakes – improvements of 2 or 3 orders of magnitude are doable just by not messing up.

Now, where everything runs in the cloud, things look a bit different. Since more and more services switch to a pay per use model, reducing the computational time and the memory usage has a direct impact on the price we need to pay. In a time where everyone wants to cut cost, we better take a good look at our applications and improve them where possible (and reasonable).

When should we run our performance tests?

Ideally on a regular basis when our unit-, integration-, and acceptance tests pass. It does not help much to start with performance testing when the functionality does not work. We want the working application to run fast, not a fast thing that does not work.

Getting Started with Performance Testing

.Net (Core) and ASP.NET Core offer a powerful framework for building high-performance web applications. But even the performance-optimised frameworks need thorough testing to shine. Here is how we can approach performance testing with our applications:

  1. Define Your Goals Before diving into testing, it is crucial to define what success looks like. Are you aiming for a specific response time? Do you need to support a certain number of concurrent users? Clear goals will guide your testing efforts and help you measure success. Remember: no clear goals, no chance to succeed!

  2. Set Up a Realistic Environment Testing in an environment that closely mirrors production is key. This means using similar hardware, software configurations, and network conditions. The closer your test environment is to the real world, the more accurate your results will be.

  3. Choose the Right Tools There are several tools available for performance testing ASP.NET Core applications. Over the next weeks we will look at these tools:

    • Bombardier, a small and fast tool to generate load.
    • NBomber, a tool that lets us write complex test scenarios.
    • .Net diagnostic tools to see what is going on inside our applications.
    • BenchmarkDotNet to optimize the bottlenecks we find.
  4. Create Realistic Test Scenarios Your tests should mimic real-world usage as closely as possible. This includes varying user loads, different types of user interactions, and concurrent requests. We can DDoS our applications with Bombardier and code the more realistic scenarios with NBomber.

  5. Monitor and Analyse Running the tests is just the beginning. Monitoring tools can help you track performance metrics such as response time, throughput, and resource utilization. Analysing these metrics will help us to identify bottlenecks and areas we should improve.

  6. Optimise Based on the Findings Once we have identified performance issues, it is time to optimize. This might involve refactoring code, implementing caching strategies, optimizing database queries, or using asynchronous processing to improve responsiveness.

  7. Verify Optimising code is good, but make sure that you verify the changes as part of the whole application. Only when the little optimisation also works in the whole application did we improve the performance.

  8. Continuous Testing Performance testing should not be a one-time event. Integrate it into your continuous integration/continuous deployment (CI/CD) pipeline to catch regressions early and ensure that your application remains performant as it evolves.

And what of the above is really needed?

In a time where many developers would be happy to have a production system that is separated from the testing environment, the points in the list above about environment and realistic use-cases seems like a dream. While it would be best to get reliable results, we can tweak it a bit and still profit from performance testing.

We can run the performance tests on our developer machines. Yes, the results are not directly comparable and our load producing tool fights for the same resources as our application. Nonetheless, we can measure the performance and interpolate the results to the production – at least to a useful extend.

We can also cut down on the realistic usage patterns and look what happens if we just flood the application with requests. Although this reduces the informative value and comparability with production, we can still improve the performance of our application.

The challenge here is that we need to know what we do, and that this knowledge comes from experience. But we need to get that experience from somewhere and may not get the optimal environment before we could show that performance testing has a meaningful impact on the cost. To solve this catch-22, we have to start small, learn and prove that this endeavour is worthwhile.

Let us start the adventure

Performance testing is not just a technical task; it is a critical part of delivering a high-quality user experience. By treating it with the same importance as other aspects of development, we can ensure that our web applications are not only functional but also fast, reliable, and ready to scale.

Over the next weeks we explore the different tools, techniques and challenges we face with performance testing. Next week we explore a first tool to put some load on our applications.