Struct FeedStats

Source
#[repr(align(64))]
pub struct FeedStats { pub messages_processed: u64, pub messages_per_second: f64, pub avg_process_latency_ns: u64, pub max_process_latency_ns: u64, pub p99_process_latency_ns: u64, pub dropped_messages: u64, pub last_update_time: u64, pub memory_usage_bytes: usize, /* private fields */ }
Expand description

Performance statistics for feed processing in HFT applications

This structure provides comprehensive statistics for monitoring, tuning, and debugging high-frequency trading data feeds. It tracks latency, throughput, and resource usage metrics that are critical for HFT operations.

Key features:

  • Zero-allocation percentile calculations using fixed-size arrays
  • Efficient EWMA (Exponentially Weighted Moving Average) for smooth metrics
  • Cache-line alignment for optimal CPU cache efficiency
  • Detailed memory usage tracking for resource monitoring
  • Thread-safe and lock-free metrics updates

§Performance Characteristics

The statistics collection is designed to have minimal impact on the critical path:

  • O(1) update operations for most metrics
  • O(n log n) for percentile calculations but limited to small fixed-size arrays
  • Zero heap allocations during normal operation
  • Minimal cache contention through 64-byte alignment

§Example Usage

use rusty_feeder::feeder::FeedStats;

// Create new statistics tracker
let mut stats = FeedStats::default();

// Update with a latency sample
stats.add_latency_sample(250); // 250 nanoseconds

// Track memory usage
stats.update_memory_usage(1024); // 1KB

// Print current statistics
println!("Avg latency: {}ns, P99: {}ns, Max: {}ns",
    stats.avg_process_latency_ns,
    stats.p99_process_latency_ns,
    stats.max_process_latency_ns);

Fields§

§messages_processed: u64

Total messages processed

§messages_per_second: f64

Messages processed per second (smoothed)

§avg_process_latency_ns: u64

Average processing latency (nanoseconds)

§max_process_latency_ns: u64

Maximum processing latency observed (nanoseconds)

§p99_process_latency_ns: u64

99th percentile processing latency (nanoseconds)

§dropped_messages: u64

Total dropped messages

§last_update_time: u64

Last update timestamp (nanoseconds)

§memory_usage_bytes: usize

Memory usage for this feed (bytes)

Implementations§

Source§

impl FeedStats

Source

pub fn add_latency_sample(&mut self, latency_ns: u64)

Add a new latency sample and update all latency statistics

This method efficiently updates all latency-related metrics in one call:

  • Exponentially Weighted Moving Average (EWMA) for stable average latency
  • Maximum observed latency
  • 99th percentile latency using a rolling window

Latency metrics are critical for high-frequency trading systems where microsecond or even nanosecond differences can impact trading performance.

§Parameters
  • latency_ns - The measured latency in nanoseconds
§Performance Characteristics
  • Updating avg and max latency is O(1)
  • P99 calculation is O(n log n) but is only performed when enough samples are collected
  • Uses fixed-size arrays (zero heap allocation)
  • The implementation uses an insertion sort for small arrays which is more efficient than quicksort for arrays of size ~100 elements
Source

pub const fn increment_dropped(&mut self)

Increment the count of dropped messages

This method should be called whenever a message is dropped due to errors, buffer overflow, or other exceptional conditions. Tracking dropped messages is critical for high-frequency trading systems to detect data quality issues.

§Performance Impact

This operation is O(1) and has minimal performance impact.

Source

pub const fn increment_processed(&mut self)

Increment the count of processed messages

This method should be called for every successfully processed message. The counter is used to calculate throughput and other performance metrics.

§Performance Impact

This operation is O(1) and has minimal performance impact.

Source

pub const fn update_memory_usage(&mut self, new_bytes: usize)

Update the memory usage estimate for resource monitoring

This method applies an exponentially weighted moving average (EWMA) to produce a stable estimate of memory usage over time, which is useful for detecting memory leaks and tracking resource utilization.

§Parameters
  • new_bytes - The latest memory usage sample in bytes
§Notes

The EWMA formula used gives 90% weight to historical data and 10% to the new sample, which provides good stability while still responding to significant changes. This approach is particularly useful for high-frequency trading applications where small variations in memory usage are expected but sustained trends are important to track.

Memory usage is tracked per feed, allowing for granular monitoring of different market data streams.

Trait Implementations§

Source§

impl Clone for FeedStats

Source§

fn clone(&self) -> FeedStats

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FeedStats

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for FeedStats

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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.

§

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

§

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
§

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> ErasedDestructor for T
where T: 'static,