Skip to content

Introduce UtilizationMonitor.#1

Merged
ioquatix merged 4 commits intomainfrom
utilization_monitor
Mar 11, 2026
Merged

Introduce UtilizationMonitor.#1
ioquatix merged 4 commits intomainfrom
utilization_monitor

Conversation

@samuel-williams-shopify
Copy link
Copy Markdown
Contributor

@samuel-williams-shopify samuel-williams-shopify commented Mar 6, 2026

Adds a UtilizationMonitor class that efficiently collects and aggregates utilization metrics from worker processes using shared memory. Workers write metrics directly to shared memory segments, and the supervisor reads and aggregates them by service name.

  • Shared Memory-Based: Uses memory-mapped files (IO::Buffer) for efficient, zero-copy metric collection, minimal overhead for services to publish metrics.
  • Automatic Resizing: Dynamically grows the shared memory file when segments run out (configurable growth factor).
  • Service Aggregation: Aggregates metrics from multiple workers by service name.
  • Graceful Error Handling: Handles worker registration failures and missing workers without crashing.
  • Flexible Schema: Each service publishes metrics according to a well defined schema in shared memory.

Architecture

  • UtilizationMonitor: Main class that manages worker registration and metric aggregation.
  • SegmentAllocator: Internal class that manages shared memory segment allocation, freeing, and automatic resizing.
  • Integration: Works with async-utilization gem - workers use Async::Utilization::Observer to write metrics to shared memory.

Usage

monitor = Async::Service::Supervisor::UtilizationMonitor.new(
  path: "utilization.shm",
  size: IO::Buffer::PAGE_SIZE * 8,
  segment_size: 512
)

# Register workers as they connect:
monitor.register(supervisor_controller)

# Get aggregated metrics by service name:
status = monitor.status
# => {utilization_monitor: {"service_name" => {connections_total: 100, connections_active: 5}}}

# Remove workers when they disconnect:
monitor.remove(supervisor_controller)

Types of Changes

  • New feature.

Contribution

@samuel-williams-shopify
Copy link
Copy Markdown
Contributor Author

cc @ivoanjo you might be interested in the design of this feature.

@ivoanjo
Copy link
Copy Markdown

ivoanjo commented Mar 9, 2026

👀 This is super cool and I've been thinking we might want/need something like this for dd-trace-rb as well!

@ioquatix ioquatix force-pushed the utilization_monitor branch from 91df406 to 08091b4 Compare March 11, 2026 00:51
@ioquatix ioquatix force-pushed the utilization_monitor branch from 08e8d2b to 9bc2643 Compare March 11, 2026 01:31
@ioquatix ioquatix merged commit 72b97be into main Mar 11, 2026
34 of 40 checks passed
@ioquatix ioquatix deleted the utilization_monitor branch March 11, 2026 02:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants