July 2017
Beginner to intermediate
340 pages
7h 43m
English
For some microservices, it can also be useful to get performance metrics inside the code.
New Relic, for instance, will track Jinja2 and database call performances by wrapping some calls inside Flask to measure how long it takes to generate a template or perform a database call.
But adding your instrumentation inside the code needs to be done carefully if that instrumentation ships in production. Slowing down the service is easy. For instance, it's unthinkable to use Python built-in profilers because they add a significant overhead.
A simple pattern is to measure the time taken by some of your functions explicitly.
In the following example, the @timeit decorator will collect execution times for the fast_stuff() ;and some_slow_stuff() ...