Profiling is an important tool for when we decide to scale the application. Before scaling, we want to know whether any process is a bottleneck and affects the overall performance. Python has a built-in profiler, cProfile, that can do the job for us, but to make life easier, werkzeug has ProfilerMiddleware, which is written over cProfile. In this recipe, we will use ProfilerMiddleware to determine whether there is anything that affects the performance.
Using profiling to find bottlenecks
Getting ready
We will use the application from the previous recipe and add ProfilerMiddleware to a new file named generate_profile.py.