How we built an async-aware Python profiler
- Datadog Python profiler
- ddtrace
- Tachyon
- Stack v2
AI Summary
Datadog redesigned its Python profiler to support asynchronous code built on asyncio, addressing the limitation where traditional flame graphs lose relationships between asynchronous tasks. By constructing stacked stacks that link tasks to their execution context and reducing profiling overhead by more than 60% using optimizations like string interning and removing C++ exceptions, the profiler accurately captures performance data in production services.
Key Takeaways
- Traditional flame graphs break down in async code because a single thread can execute multiple suspended/resumed coroutines, preventing a single logical execution stack.
- The profiler introduces stacked stacks, which build frame stacks per task and map dependency trees to show what coroutines are blocked on.
- To avoid high overhead from numerous process_vm_readv system calls when scanning numerous active tasks, engineers eliminated C++ exceptions and interned strings, cutting overhead significantly.
Why it matters
Asynchronous Python services make up a large portion of modern backend infrastructure, yet traditional profiling tools fail to trace execution flows across decoupled asyncio tasks. Understanding how to build async-aware profiling models and reduce systemic monitoring overhead provides critical design lessons for engineers building high-performance observability tools.
Conversation0
What would you add from your experience?
Checking your session…
Every good conversation starts with one perspective.