Is there a production-safe way to measure production time with Python?

I want to be able to apply Python applications so that I know:

  • Page generation time.
  • Percentage of time spent on external queries (mysql, api calls).
  • The number of mysql queries that were MySQL queries.

I want this data to be produced (not offline profiling) - because the time spent in different places will be different at boot time.

In PHP, I can do this using XHProf or Instrument-for-php. In Ruby on Rails / .NET / Java, I can do this with a new relic.

Is there such a package for Python or django?

+4
source share
3 answers

Yes, it is quite possible. For instance. use some kind of magic switch in the url, for example "profile-me", which launches profiling in Django middleware.

There are several fragments on the Internet, for example: http://djangosnippets.org/snippets/70/ or modules like this: http://code.google.com/p/django-profiling/ - but I haven’t used any of them, so I cannot recommend anything.

In any case, the approach they use is similar to what I am doing, i.e. use the Python Hotshot profile module in middleware that wraps your view. For the MySQL part, you can simply use connection.queries in Django.

The good thing about Hotshot is that its output can be viewed using Kcachegrind, as here: http://www.rkblog.rk.edu.pl/w/p/django-profiling-hotshot-and-kcachegrind/

+1
source

The new Relic now had a package for Python, including Django via mod_wsgi.

https://support.newrelic.com/help/kb/python

+1
source

django-prometheus is a good choice for handling workloads, especially in containerized environments such as Kubernetes. Out of the box, there is middleware for tracking delays and request counters (using the viewing method), as well as access time to the database and cache. This will not be a good solution to keep track of which requests are actually being executed, but exactly where the logging solution comes into play, such as ELK . If this helps, I wrote a post that explains how to add custom metrics to a Django application .

0
source

All Articles