FARGOS/VISTA Object Management Environment Core  ..
FARGOS/VISTA Object Management Environment Core Table of Contents
RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND > Class Template Reference

Sliding window rate counter that takes O(1) time. More...

#include <rate_counter.hpp>

Public Member Functions

void set_interval (uint64_t units) OME_ALWAYS_INLINE
 Set the size of the interval window in units of UNITS_PER_SECOND. More...
 
 RateCounterForInterval (EVENT_COUNT_TYPE max_events, uint64_t units)
 Construct an O(1) RateCounterForInterval object. More...
 
 ~RateCounterForInterval ()
 
uint32_t get_interval () const OME_ALWAYS_INLINE
 Get the length of the interval in units of UNITS_PER_SECOND. More...
 
uint32_t get_interval_in_nanoseconds () const OME_ALWAYS_INLINE
 Get the length of the interval in nanoseconds. More...
 
EVENT_COUNT_TYPE get_events_in_interval () const OME_ALWAYS_INLINE
 Get total number of events in the interval. More...
 
EVENT_COUNT_TYPE get_maximum_rate () const OME_ALWAYS_INLINE
 Get the maximum permitted events per interval. More...
 
void set_maximum_rate (EVENT_COUNT_TYPE max_events) OME_ALWAYS_INLINE
 Set the maximum permitted events per interval. More...
 
EVENT_COUNT_TYPE add_events_to_slot (EVENT_COUNT_TYPE count=1, const struct timespec *now=nullptr)
 Add events to an interval. More...
 

Private Types

enum  { ONE_BILLION = 1000000000UL, NS_PER_UNITS = ONE_BILLION / UNITS_PER_SECOND }
 

Private Attributes

EVENT_COUNT_TYPE * event_slots
 storage for events-per-interval counters More...
 
EVENT_COUNT_TYPE events_in_interval
 total events currently in the interval More...
 
EVENT_COUNT_TYPE rate_threshold
 maximum permitted events in the interval More...
 
uint64_t interval_in_units
 interval duration in UNITS_PER_SECOND More...
 
uint64_t interval_in_nanoseconds
 interval duration in nanoseconds More...
 
uint64_t interval_threshold_in_seconds
 coarse interval duration in seconds More...
 
struct timespec last_time_used
 time of last recorded event More...
 
uint32_t last_slot_used
 round-robin subscript for slot table More...
 
bool changed_slot
 enables optimization if events are widely spaced More...
 

Detailed Description

template<typename EVENT_COUNT_TYPE = int32_t, uint64_t UNITS_PER_SECOND = 1>
class RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >

Sliding window rate counter that takes O(1) time.

Parameters
EVENT_COUNT_TYPEspecifies the type to be used to hold the number of events within the interval. Typically this is an int32_t, but it might be a floating point or fixed-point value in some applications.
UNITS_PER_SECONDdefines the granularity of the time units to be tracked.
Note
EVENT_COUNT_TYPE must be able to represent negative values as this is used by the return value from add_events_to_slot().

Member Enumeration Documentation

◆ anonymous enum

template<typename EVENT_COUNT_TYPE = int32_t, uint64_t UNITS_PER_SECOND = 1>
anonymous enum
private
Enumerator
ONE_BILLION 
NS_PER_UNITS 

Constructor & Destructor Documentation

◆ RateCounterForInterval()

template<typename EVENT_COUNT_TYPE = int32_t, uint64_t UNITS_PER_SECOND = 1>
RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::RateCounterForInterval ( EVENT_COUNT_TYPE  max_events,
uint64_t  units 
)
inline

Construct an O(1) RateCounterForInterval object.

Parameters
max_eventsspecifies the maximum permissible events within an interval.
unitsspecifies the length of the interval in units of UNITS_PER_SECOND.

References RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::event_slots, RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::rate_threshold, and RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::set_interval().

◆ ~RateCounterForInterval()

template<typename EVENT_COUNT_TYPE = int32_t, uint64_t UNITS_PER_SECOND = 1>
RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::~RateCounterForInterval ( )
inline

Member Function Documentation

◆ add_events_to_slot()

template<typename EVENT_COUNT_TYPE = int32_t, uint64_t UNITS_PER_SECOND = 1>
EVENT_COUNT_TYPE RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::add_events_to_slot ( EVENT_COUNT_TYPE  count = 1,
const struct timespec *  now = nullptr 
)
inline

◆ get_events_in_interval()

template<typename EVENT_COUNT_TYPE = int32_t, uint64_t UNITS_PER_SECOND = 1>
EVENT_COUNT_TYPE RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::get_events_in_interval ( ) const
inline

Get total number of events in the interval.

References RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::events_in_interval.

◆ get_interval()

template<typename EVENT_COUNT_TYPE = int32_t, uint64_t UNITS_PER_SECOND = 1>
uint32_t RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::get_interval ( ) const
inline

Get the length of the interval in units of UNITS_PER_SECOND.

References RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::interval_in_units.

◆ get_interval_in_nanoseconds()

template<typename EVENT_COUNT_TYPE = int32_t, uint64_t UNITS_PER_SECOND = 1>
uint32_t RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::get_interval_in_nanoseconds ( ) const
inline

Get the length of the interval in nanoseconds.

References RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::interval_in_nanoseconds.

◆ get_maximum_rate()

template<typename EVENT_COUNT_TYPE = int32_t, uint64_t UNITS_PER_SECOND = 1>
EVENT_COUNT_TYPE RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::get_maximum_rate ( ) const
inline

Get the maximum permitted events per interval.

References RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::rate_threshold.

◆ set_interval()

◆ set_maximum_rate()

template<typename EVENT_COUNT_TYPE = int32_t, uint64_t UNITS_PER_SECOND = 1>
void RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::set_maximum_rate ( EVENT_COUNT_TYPE  max_events)
inline

Set the maximum permitted events per interval.

References RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::rate_threshold.

Member Data Documentation

◆ changed_slot

template<typename EVENT_COUNT_TYPE = int32_t, uint64_t UNITS_PER_SECOND = 1>
bool RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::changed_slot
private

◆ event_slots

◆ events_in_interval

template<typename EVENT_COUNT_TYPE = int32_t, uint64_t UNITS_PER_SECOND = 1>
EVENT_COUNT_TYPE RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::events_in_interval
private

◆ interval_in_nanoseconds

template<typename EVENT_COUNT_TYPE = int32_t, uint64_t UNITS_PER_SECOND = 1>
uint64_t RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::interval_in_nanoseconds
private

◆ interval_in_units

template<typename EVENT_COUNT_TYPE = int32_t, uint64_t UNITS_PER_SECOND = 1>
uint64_t RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::interval_in_units
private

◆ interval_threshold_in_seconds

template<typename EVENT_COUNT_TYPE = int32_t, uint64_t UNITS_PER_SECOND = 1>
uint64_t RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::interval_threshold_in_seconds
private

◆ last_slot_used

template<typename EVENT_COUNT_TYPE = int32_t, uint64_t UNITS_PER_SECOND = 1>
uint32_t RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::last_slot_used
private

◆ last_time_used

template<typename EVENT_COUNT_TYPE = int32_t, uint64_t UNITS_PER_SECOND = 1>
struct timespec RateCounterForInterval< EVENT_COUNT_TYPE, UNITS_PER_SECOND >::last_time_used
private

◆ rate_threshold


The documentation for this class was generated from the following file:
Generated: Tue Jul 28 2020 16:03:27
Support Information