Skip to content

yfractal/sdb

Repository files navigation

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?

  1. Minimal Impact: SDB does not affect the target application's performance.
  2. Event Tagging: SDB supports event tagging, making it easier to trace and identify slow functions.
  3. High Accuracy: SDB offers precision down to microseconds.

Instrumentation libraries like 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

Image

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

roda

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.

NOTICE

SDB is still in the experimental stage. Rather than focusing on ease of use and stability, I am exploring additional use cases, such as detecting concurrency issues or delays caused by GVL.

About

A Ruby stack profiler without GVL.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published