JayBeams
0.1
Another project to have fun coding.
|
Keep a histogram of observed event rates. More...
#include <event_rate_histogram.hpp>
Public Types | |
Type traits. | |
typedef integer_range_binning< std::uint64_t > | binning_strategy |
typedef histogram< binning_strategy, counter_type > | rate_histogram |
Public Member Functions | |
event_rate_histogram (std::uint64_t max_expected_rate, duration_type measurement_period, duration_type sampling_period=duration_type(1)) | |
Constructor. More... | |
void | sample (duration_type ts) |
Record a new sample. More... | |
std::uint64_t | last_rate () const |
Get the last sample, if any. More... | |
Private Attributes | |
event_rate_estimator< duration_type, rate_counter_type > | rate_ |
std::uint64_t | last_rate_ |
Additional Inherited Members | |
![]() | |
typedef std::vector< counter_type > | counters |
The type used to store the bins. More... | |
typedef integer_range_binning< std::uint64_t > | binning_strategy |
typedef binning_strategy::sample_type | sample_type |
typedef counter_type | counter_type |
![]() | |
histogram (binning_strategy const &mapping=binning_strategy()) | |
Construct a histogram given a mapping strategy. More... | |
std::uint64_t | nsamples () const |
Return the number of samples observed to this point. More... | |
sample_type | observed_min () const |
Return the smallest sample value observed to this point. More... | |
sample_type | observed_max () const |
Return the largest sample value observed to this point. More... | |
sample_type | estimated_mean () const |
Estimate the mean of the sample distribution. More... | |
sample_type | estimated_quantile (double q) const |
Estimate a quantile of the sample distribution. More... | |
std::uint64_t | underflow_count () const |
Return the number of samples smaller than the histogram range. More... | |
std::uint64_t | overflow_count () const |
Return the number of samples larger than the histogram range. More... | |
histogram_summary | summary () const |
Return a simple summary. More... | |
void | sample (sample_type const &t) |
Record a new sample. More... | |
void | weighted_sample (sample_type const &t, counter_type weight) |
Record a new sample. More... | |
void | reset () |
Reset all counters. More... | |
Keep a histogram of observed event rates.
This class collects running statistics about event rates. While an event_rate_estimator computes the number of events in the last X seconds, this class keeps a tally of the observed event rates, which can be used to build median, maximum and any other quantile of the message rate.
The user specifies the maximum message rate to keep at full resolution, any rate above that value is simply recorded in the histogram overflow bucket.
For example to keep track of per-millisecond message rate you would instantiate the class as follows:
The user of the class must provide a maximum expected message rate, higher rates are recorded in a single 'overflow' bucket. If you guess too high on the rate the rate_histo object would consume more memory than necessary. If you guess too low the high quantiles might be less accurate. Memory requirements are low (the data structure is basically a vector of ints), but can be an issue if you create many histograms (for example, one histogram per security when analyzing a market data feed).
duration_type | Define the units used to measure time. This class assumes all events are timestamped with a class compatible with std::chrono::duration<>, against some epoch that is defined by convention but not explicitly provided to the class. This is convenient because some feeds just provide microseconds or nanoseconds since midnight, while others use microseconds since the Unix Epoch. If you are using some kind of std::chrono::time_point<> object for your timestamps simply call time_since_epoch() on the object before sampling. |
counter_type | The type used in the histogram counters. For most applications int is adequate, but you may use a smaller type if (a) you are memory constrained, and (b) you do not expect high values in the counters. You might also consider a wider integral type if you expect very high number of events. |
rate_counter_type | The type used in the event rate counters. Similar tradeofss as counter_type. |
Definition at line 68 of file event_rate_histogram.hpp.
typedef integer_range_binning<std::uint64_t> jb::event_rate_histogram< duration_type, counter_type, rate_counter_type >::binning_strategy |
Definition at line 75 of file event_rate_histogram.hpp.
typedef histogram<binning_strategy, counter_type> jb::event_rate_histogram< duration_type, counter_type, rate_counter_type >::rate_histogram |
Definition at line 76 of file event_rate_histogram.hpp.
|
inline |
Constructor.
max_expected_rate | The histogram is kept at full resolution up to this rate, any periods with more events are counted only in the overflow bin. If this value is too low for the observed rates, the high quantiles may not be very accurate. |
measurement_period | over what period we measure event rates. |
sampling_period | how often do we measure event rates. |
Definition at line 89 of file event_rate_histogram.hpp.
|
inline |
Get the last sample, if any.
Definition at line 106 of file event_rate_histogram.hpp.
|
inline |
Record a new sample.
Definition at line 98 of file event_rate_histogram.hpp.
Referenced by jb::offline_feed_statistics::record_sample().
|
private |
Definition at line 128 of file event_rate_histogram.hpp.
Referenced by jb::event_rate_histogram< std::chrono::nanoseconds, std::int64_t >::last_rate(), and jb::event_rate_histogram< std::chrono::nanoseconds, std::int64_t >::sample().
|
private |
Definition at line 127 of file event_rate_histogram.hpp.
Referenced by jb::event_rate_histogram< std::chrono::nanoseconds, std::int64_t >::sample().