Chapter 8

Maximizing Your Code’s Performance

SO FAR, THIS book has stressed the importance of testing your application from every possible angle to ensure that your code works as expected and delivers quality to your end users or customers. Including a thorough testing process in your development cycle helps you deliver a product that meets your clients’ needs. What hasn’t been covered so far is how you can ensure that the code you write will actually perform under real-world conditions.

Say you are creating an HTTP service to deliver some data; the code you write for this service may perform well in the small-scale testing you do at the unit level. How will your application perform when you scale up from only a couple of requests per second to thousands, hundreds of thousands, and possibly millions? This is where performance testing comes into play and in particular the use of the JMeter tool. JMeter allows you to mimic some of the real-world conditions you expect your application to face to reveal the kind of response times your application will deliver by generating load on your application. As you scale up the amount of requests per second, is there a tipping point where suddenly the response times increase and performance suffers?

These are the kinds of questions you can answer with performance testing, which ideally takes place before your application has reached your end users. This gives you a chance to optimize your application’s performance, using the code profiling ...

Get Testing Python: Applying Unit Testing, TDD, BDD and Acceptance Testing now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.