Getting Started
This guide explains how to get started with async-utilization to track high-performance utilization metrics for Async services using shared memory.
Installation
Add the gem to your project:
$ bundle add async-utilization
Core Concepts
async-utilization provides a convenient interface for tracking utilization metrics that can be synchronized to shared memory for inter-process communication.
The key components are:
class Async::Utilization::Registry: Thread-local singleton for emitting metrics.class Async::Utilization::Schema: Defines the binary layout for serialization.class Async::Utilization::Observer: Writes metrics to shared memory using the schema.class Async::Utilization::Metric: Caches metric value and fast path for direct buffer updates.
Basic Usage
The recommended way to use async-utilization is to get a cached metric reference and use it:
require "async/utilization"
# Get metrics:
total_requests = Async::Utilization.metric(:total_requests)
active_requests = Async::Utilization.metric(:active_requests)
# Increment a metric:
total_requests.increment
# Increment with auto-decrement:
active_requests.increment do
# Handle request - automatically decrements when block completes
end
Metrics are tracked in memory and can be accessed programmatically. However, for inter-process communication (e.g., with a supervisor process), you'll want to use a shared memory observer.