[][src]Module stats::thread_local_aggregator

This module provides the means to define stats that are thread local and to schedule a periodic aggregation process of those stats.

The assumption behind this library is that there are much more writes to the stats than there are reads. Because of that it's vital that writes are quick while reads can be a little relaxed, so that recent writes might not be visible in the read until an aggregation is called.

Thread local stats help with the speed goal of writes - except for infrequent reads no one is racing with the current thread to access those values. As for periodic aggregation - this is achieved via a future running every second thanks to tokio timer and aggregating every thread local stat. The future must be spawned on tokio in order for the aggregation to work.

Structs

StatsScheduledError

This error is returned to indicate that the stats scheduler was already retrieved before and potentially is already running, but might be retrieved again from this error

StatsScheduledErrorPreview

This error is returned to indicate that the stats scheduler was already retrieved before and potentially is already running, but might be retrieved again from this error

Functions

create_map

Creates the ThreadMap and registers it for periodic calls for aggregation of stats

schedule_stats_aggregation

Upon the first call to this function it will return a future that results in periodically calling aggregation of stats. On subsequent calls it will return Error::StatsScheduled that contain the future, so that the caller might still use it, but knows that it is not the first this function was called.

schedule_stats_aggregation_preview

Upon the first call to this function it will return a future that results in periodically calling aggregation of stats. On subsequent calls it will return Error::StatsScheduled that contain the future, so that the caller might still use it, but knows that it is not the first this function was called.

Type Definitions

Scheduler

Type alias for the future that must be spawned on tokio.