TimelessMetrics.Buffer (timeless_metrics v6.0.10)

Copy Markdown View Source

Sharded ETS write buffer.

Incoming metrics land in one of N ETS shards (selected by series_id). Each shard flushes periodically or when a point threshold is exceeded, handing accumulated points to the SegmentBuilder for compression.

Supports backpressure: when the SegmentBuilder mailbox exceeds a configurable threshold, writes return {:error, :backpressure}.

Summary

Functions

Get the current point count in this shard's buffer.

Returns a specification to start this module under a supervisor.

Read buffered points for a series within a time range. Lock-free.

Write a point to the appropriate shard's ETS table. Lock-free.

Bulk-write pre-resolved points to a shard. Called by write_batch.

Functions

buffer_size(shard_name)

Get the current point count in this shard's buffer.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

read_points(shard_name, series_id, from, to)

Read buffered points for a series within a time range. Lock-free.

start_link(opts)

write(shard_name, series_id, timestamp, value)

Write a point to the appropriate shard's ETS table. Lock-free.

Returns :ok on success or {:error, :backpressure} if the SegmentBuilder is overwhelmed.

write_bulk(shard_name, points)

Bulk-write pre-resolved points to a shard. Called by write_batch.

points is a list of {series_id, timestamp, value} tuples. Single ETS insert + single atomics update for the whole batch.