Python profiling and performance tuning in production
summary
Pinterest cuts front-end latency and fleet size by over 40% fleet reduction using under 100 lines of Python, after finding 70% of latency comes from mixing CPU work with gevent cooperative multitasking. Diagnosis uses cProfile call graphs, line_profiler, a SIGVTALRM-based statistical sampler (stack-sampling converted to flame graphs) and Improv for statistical line hits. Production sampling runs ~15 minutes per process, targets a 33% increase in requests per host, and yields the reported 30–40% cost and latency wins.
AI-written summary · about
chapters (16)
- 0:00Introduction and context
- 1:05Problem with high latency
- 2:10Gevent and cooperative multitasking
- 5:38Demo of latency degradation
- 8:47Impact of blocking calls
- 10:08Reducing CPU usage in API
- 11:30Profiling tools overview
- 12:14CProfile API profiler
- 14:40Line profiler for CPU bottlenecks
- 16:45Statistical profilers
- 18:31Stack sampler and flame graphs
- 20:58Improv statistical line profiling
- 22:00Production profiling setup
- 23:23Case study deep copy removal
- 25:11Detecting regressions visually
- 26:12Results and conclusion
