Skip to content

docs: plan Prometheus metrics on single-writer shards of the arena - #33

Draft
lisachenko wants to merge 1 commit into
mainfrom
feature/fervent-cray-hs876l
Draft

lisachenko wants to merge 1 commit into
mainfrom
feature/fervent-cray-hs876l

Conversation

@lisachenko

Copy link
Copy Markdown
Owner

Summary

This is a plan only, with no implementation yet. docs/prometheus-metrics-plan.md sets out how to expose Prometheus/OpenMetrics metrics from every worker of a fork family through the arena:

  • Core design: each worker claims a shard, and each series has one cell per shard. The hot path is a plain store through a view that is bound once per process. It takes no lock, and no update is lost because each word has a single writer. A scrape adds up the shards.
  • Repository split:
    • Generic primitives go here. These are an Arena float view and process recovery, Ipc\ShardTable, Ipc\CellPlane and Ipc\FixedIndex.
    • Everything that knows about Prometheus goes in a new repository that depends on this one.
  • Types covered: Counter, Gauge (seven aggregation modes), classic Histogram, GaugeHistogram, Summary (windowed mergeable quantiles), native histograms, Info, StateSet, Unknown, exemplars and _created.
  • Exposition and endpoints:
    • Text 0.0.4, OpenMetrics 1.0 and protobuf, selected by content negotiation.
    • An in-band handler, PSR-15 middleware or a forked exporter process.
    • A deployment matrix covering FPM with preload, pcntl/Swoole, RoadRunner and FrankenPHP.
  • Delivery: a memory budget formula, phases with gates, and open questions for the maintainer.

Evidence

spikes/s18-sharded-metric-cells.php measures the paths the design chooses between. It was run on PHP 8.5 NTS on a 4 vCPU VM:

Path ns / increment
AtomicInt::add(), uncontended ~500
AtomicInt::add(), 4 workers on one cell 6 000–7 000
Arena::readWord() + writeWord() ~110 (also loses 46–77 % of updates when shared)
bound view, one cell per worker ~17 uncontended, ~45–60 with 4 workers
bound view, cells 8 B apart (false sharing) ~125–140

With one writer per cell, the totals were exact on every run.

Notable findings recorded in the plan

  • PersistentStore::bootShared() needs a live Arena object, so an FPM worker cannot reach an arena that was created in opcache.preload. Supporting FPM will need an arena recovery entry point.
  • RoadRunner starts its workers with exec rather than fork, so they are not a fork family. The README's "blessed setups" should be checked against this.
  • A view cast out of a temporary holder CData keeps pointing into that holder. Once the holder is freed, writes silently go nowhere.

Test plan

  • The spike runs to exit 0 against this package's Arena (twice)
  • Spike S18 has not yet been re-run on PHP 8.4. That re-run is part of Phase 0 of the plan.

Generated by Claude Code

Adds the implementation plan for Prometheus/OpenMetrics metrics over the
fork-shared arena (types, layout, exposition, endpoints, phases and gates)
and spike S18, which measures the increment paths it chooses between.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FxhC1CUGTf4RrRrNgErXk2
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.

2 participants