PyGrunn: monitoring and profiling Flask apps - Patrick Vogel & Bogdan Petre

Tags: pygrunn, python

(One of my summaries of a talk at the 2019 PyGrunn conference).

Patrick and Bogdan are students at Groningen University and they made the Flask Monitoring Dashboard. Some questions you might be interested in:

  • What is the performance of your flask-based apps?

  • How much is my web app being used?

  • Mean response time per endpoint?

  • Are there a lot of outliers? Most customers might have 20 items and one customer might have a couple of thousands: that’ll hurt performance for only that specific customer. Important to understand.

  • Monitor performance improvements in case you deploy a new version.

What are your options?

  • Commercial monitoring like google analytics or pingdom.

  • Write your own monitoring in flask middleware.

  • No middleware.

  • Best: use the flask monitoring dashboard!

It offers several levels of monitoring that you can configure per endpoint. From just monitoring the last time the endpoint has been called to full profiling including outlier detection. They showed a webpage with the profiling information: it sure looked useful. As an example, there’s a table view (hours vertically, days of the week horizontally) showing the relative usage per day/hour.

It works by “monkeypatching” the view functions. Flask has an internal dictionary with all the view functions! When profiling, a separate thread is started that periodically collects stacktrace info from the function being monitored.

Such monitoring of course has a performance impact. They’re actually researching that right now. The lower levels of monitoring (“time it was last used” and “amount of usage”) have no discernable impact. The two levels that do profiling have more overhead. For cpu/memory intensive tasks, the overhead is around 10%. For disk intensive tasks, it can hit 60%.

 
vanrees.org logo

About me

My name is Reinout van Rees and I work a lot with Python (programming language) and Django (website framework). I live in The Netherlands and I'm happily married to Annie van Rees-Kooiman.

Weblog feeds

Most of my website content is in my weblog. You can keep up to date by subscribing to the automatic feeds (for instance with Google reader):