Wednesday, April 18, 2018

Python / Flask Performance Profiling

I've recently been doing work on some python flask web applications my team owns at work. Twice now, I've needed to acquire profiling data to help pinpoint where issues were stemming from within the code and dependencies.

In lieu of not trying to track down what I've learned / researched twice now, I'm recording my methods and tools here for future reference. Hopefully others will be able to make use of this information as well!

I've created a small and simple python flask-based webapp which makes use of Werkzeug's ProfilerMiddleware and SnakeViz to visualize a request - you can find this example and the quickstart on GitHub. After 7 quick steps, you'll be presented with something similar to below:

Generating profiling data

  • http://werkzeug.pocoo.org/docs/0.14/contrib/profiler/

Viewing profiling data

  • https://jiffyclub.github.io/snakeviz/
  • https://kcachegrind.github.io/html/Home.html