Skip to main content

PartitionMetrics

Struct PartitionMetrics 

Source
pub struct PartitionMetrics { /* private fields */ }
Expand description

Partition monitoring for detecting hot partitions and skew (SierraDB pattern)

§Design Pattern

Uses atomic operations for lock-free metric updates per partition. Tracks event counts, write latencies, and error rates per partition.

§SierraDB Context

SierraDB uses fixed partitions (32 for single-node, 1024+ for clusters). Detecting hot partitions is critical for:

  • Load balancing decisions
  • Identifying skewed hash functions
  • Capacity planning
  • Performance troubleshooting

§Imbalance Detection

A partition is considered imbalanced if it has >2x the average load. This threshold is based on SierraDB’s experience with production workloads.

§Example

let partition_metrics = PartitionMetrics::new(32);

// Record write to partition 5
let start = Instant::now();
// ... write operation ...
partition_metrics.record_write(5, start.elapsed());

// Check for imbalances
let alerts = partition_metrics.detect_partition_imbalance();
for alert in alerts {
    tracing::warn!("Partition imbalance: {}", alert.message);
}

Implementations§

Source§

impl PartitionMetrics

Source

pub fn new(partition_count: u32) -> Self

Create a new partition metrics tracker

§Arguments
  • partition_count - Number of partitions (default: 32 for single-node)
Source

pub fn with_default_partitions() -> Self

Create partition metrics with default partition count (32)

Source

pub fn record_write(&self, partition_id: u32, latency: Duration)

Record a successful write to a partition

§Arguments
  • partition_id - The partition ID (0 to partition_count-1)
  • latency - The write latency
Source

pub fn record_error(&self, partition_id: u32)

Record an error for a partition

§Arguments
  • partition_id - The partition ID (0 to partition_count-1)
Source

pub fn record_batch_write( &self, partition_id: u32, count: u64, latency: Duration, )

Record a batch write to a partition

§Arguments
  • partition_id - The partition ID (0 to partition_count-1)
  • count - Number of events in the batch
  • latency - Total latency for the batch write
Source

pub fn get_partition_stats(&self, partition_id: u32) -> Option<PartitionStats>

Get statistics for a specific partition

Source

pub fn get_all_partition_stats(&self) -> Vec<PartitionStats>

Get statistics for all partitions

Source

pub fn detect_partition_imbalance(&self) -> Vec<PartitionImbalanceAlert>

Detect partition imbalance (hot partitions)

Returns alerts for any partition with >2x average event count. This is the SierraDB pattern for detecting skew and hot partitions.

§Returns

Vector of alerts for imbalanced partitions

Source

pub fn partition_count(&self) -> u32

Get partition count

Source

pub fn total_events(&self) -> u64

Get total events across all partitions

Source

pub fn total_errors(&self) -> u64

Get total errors across all partitions

Source

pub fn uptime(&self) -> Duration

Get uptime since metrics collection started

Source

pub fn registry(&self) -> &Registry

Get the Prometheus registry for this partition metrics

Source

pub fn encode(&self) -> Result<String, Box<dyn Error>>

Encode metrics in Prometheus text format

Source

pub fn get_distribution(&self) -> HashMap<u32, u64>

Get partition distribution as a map

Source

pub fn reset(&self)

Reset all partition metrics

Trait Implementations§

Source§

impl Default for PartitionMetrics

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,