A Ruby stack profiler without GVL.
SDB: High-accuracy stack profiler for Ruby
Introduction
SDB provides high-accuracy stack profiling for Ruby applications. It can profile Ruby at microsecond (0.000001 second) intervals and offers event tagging for requests.Why Do We Need Another Stack Profiler?
- Minimal Impact: SDB does not affect the target application's performance.
- Event Tagging: SDB supports event tagging, making it easier to trace and identify slow functions.
- High Accuracy: SDB offers precision down to microseconds.
opentelemetry-ruby generate data during application runtime, and some stack profilers block application threads. These approaches can introduce delays in your application.
SDB, inspired by LDB, operates by pulling stack traces on a separate thread, which minimizes the impact on our application.
Event tagging, such as adding trace_id for Puma requests, makes it easier to identify slow functions.
Moreover, SDB can precisely identify delays, down to a single microsecond.
How it Works
The stack scanner scans the Ruby stacks without the GVL as reading an Iseq address is atomic. The symbolizer translates Iseq into function name and path and it "caches" the translation result for avoiding repeat work to achieve better performance. As it "caches" the translation result, it marks the Iseq address at each beginning of GC for avoiding incorrect results -- an Iseq has been reclaimed and the address is used by a new Iseq.
Usage Example
The image above is generated by sdb-analyzer. It represents a simple Ruby API application rendering an empty body.
The image clearly shows which methods are used and their latency, helping us understand the application's behavior and identify potential latency issues, even without prior background knowledge.