C# (CSharp) Elders.Hystrix.NET.Util Namespace

Classes

Name Description
ActualTime Provides a method to get the current time. It uses Stopwatch.
HystrixRollingNumber

A number which can be used to track counters (increment) or set values over time.

It is "rolling" in the sense that a 'timeInMilliseconds' is given that you want to track (such as 10 seconds) and then that is broken into buckets (defaults to 10) so that the 10 second window doesn't empty out and restart every 10 seconds, but instead every 1 second you have a new bucket added and one dropped so that 9 of the buckets remain and only the newest starts from scratch.

This is done so that the statistics are gathered over a rolling 10 second window with data being added/dropped in 1 second intervals (or whatever granularity is defined by the arguments) rather than each 10 second window starting at 0 again.

Performance-wise this class is optimized for writes, not reads. This is done because it expects far higher write volume (thousands/second) than reads (a few per second).

For example, on each read to getSum/getCount it will iterate buckets to sum the data so that on writes we don't need to maintain the overall sum and pay the synchronization cost at each write to ensure the sum is up-to-date when the read can easily iterate each bucket to get the sum when it needs it.

HystrixRollingNumber.Bucket Counters for a given 'bucket' of time.
HystrixRollingNumber.CumulativeSum Cumulative counters (all time) for each HystrixRollingNumberEvent used in HystrixRollingNumber.
HystrixRollingNumberEventExtensions Provides helper methods for the HystrixRollingNumberEvent enumeration.
HystrixRollingPercentile

Add values to a rolling window and retrieve percentile calculations such as median, 90th, 99th, etc.

The underlying data structure contains a circular array of buckets that "roll" over time.

For example, if the time window is configured to 60 seconds with 12 buckets of 5 seconds each, values will be captured in each 5 second bucket and rotate each 5 seconds.

This means that percentile calculations are for the "rolling window" of 55-60 seconds up to 5 seconds ago.

Each bucket will contain a circular array of long values and if more than the configured amount (1000 values for example) it will wrap around and overwrite values until time passes and a new bucket is allocated. This sampling approach for high volume metrics is done to conserve memory and reduce sorting time when calculating percentiles.

HystrixRollingPercentile.Bucket Counters for a given 'bucket' of time.
HystrixRollingPercentile.PercentileBucketData Stores the values of a bucket in HystrixRollingPercentile. It's behavior is similar to a circular array, the new items after the specified count will overwrite the oldest items.
HystrixRollingPercentile.PercentileSnapshot Stores all the values of the given buckets and provides methods to calculate percentiles.
HystrixTimer Provides timers to repeatedly call ITimerListener implementations.
LongAdder This class is currently equivalent to AtomicLong. The original implementation derive from Striped64 to implement a counter with better throughput under high contention.
LongMaxUpdater This class is currently uses AtomicLong to calculate the maximum of a series of number. The original implementation derive from Striped64 to implement a counter with better throughput under high contention.
TimerReference A reference to the started HystrixTimer so it can be stopped with the Clear() method.