C# Class Elders.Hystrix.NET.Util.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.

Datei anzeigen Open project: Elders/Hystrix.NET Class Usage Examples

Private Properties

Property Type Description
GetCurrentBucket Bucket
HystrixRollingPercentile System

Public Methods

Method Description
AddValue ( ) : void

Add value (or values) to current bucket.

GetMean ( ) : int

Gets the mean (average) of all values in the current snapshot. This is not a percentile but often desired so captured and exposed here.

GetPercentile ( double percentile ) : int

Compute a percentile from the underlying rolling buckets of values.

For performance reasons it maintains a single snapshot of the sorted values from all buckets that is re-generated each time the bucket rotates.

This means that if a bucket is 5000 milliseconds, then this method will re-compute a percentile at most once every 5000 milliseconds.

HystrixRollingPercentile ( IHystrixProperty timeInMilliseconds, IHystrixProperty numberOfBuckets, IHystrixProperty bucketDataLength, IHystrixProperty enabled ) : System

Initializes a new instance of the HystrixRollingPercentile class.

Reset ( ) : void

Force a reset so that percentiles start being gathered from scratch.

Private Methods

Method Description
GetCurrentBucket ( ) : Bucket

Gets the current bucket. If the time is after the window of the current bucket, a new one will be created. Internal because it's used in unit tests.

HystrixRollingPercentile ( ITime time, IHystrixProperty timeInMilliseconds, IHystrixProperty numberOfBuckets, IHystrixProperty bucketDataLength, IHystrixProperty enabled ) : System

Initializes a new instance of the HystrixRollingPercentile class.

Method Details

AddValue() public method

Add value (or values) to current bucket.
public AddValue ( ) : void
return void

GetMean() public method

Gets the mean (average) of all values in the current snapshot. This is not a percentile but often desired so captured and exposed here.
public GetMean ( ) : int
return int

GetPercentile() public method

Compute a percentile from the underlying rolling buckets of values.

For performance reasons it maintains a single snapshot of the sorted values from all buckets that is re-generated each time the bucket rotates.

This means that if a bucket is 5000 milliseconds, then this method will re-compute a percentile at most once every 5000 milliseconds.

public GetPercentile ( double percentile ) : int
percentile double Value such as 99 (99th percentile), 99.5 (99.5th percentile), 50 (median, 50th percentile) to compute and retrieve percentile from rolling buckets.
return int

HystrixRollingPercentile() public method

Initializes a new instance of the HystrixRollingPercentile class.
public HystrixRollingPercentile ( IHystrixProperty timeInMilliseconds, IHystrixProperty numberOfBuckets, IHystrixProperty bucketDataLength, IHystrixProperty enabled ) : System
timeInMilliseconds IHystrixProperty Number of milliseconds of data that should be tracked.
numberOfBuckets IHystrixProperty Number of buckets that the time window should be divided into.
bucketDataLength IHystrixProperty Number of values stored in each bucket.
enabled IHystrixProperty Sets whether data should be tracked and percentiles be calculated.
return System

Reset() public method

Force a reset so that percentiles start being gathered from scratch.
public Reset ( ) : void
return void