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

Afficher le fichier Open project: Elders/Hystrix.NET Class Usage Examples

Private Properties

Свойство Type Description
GetCurrentBucket Bucket
HystrixRollingNumber System
HystrixRollingNumber System

Méthodes publiques

Méthode Description
Add ( HystrixRollingNumberEvent type, long value ) : void

Add to the counter in the current bucket for the given HystrixRollingNumberEvent type.

GetCumulativeSum ( HystrixRollingNumberEvent type ) : long

Get the cumulative sum of all buckets ever since the application started without rolling for the given HystrixRollingNumberEvent type. See GetRollingSum(HystrixRollingNumberEvent) for the rolling sum.

GetRollingMaxValue ( HystrixRollingNumberEvent type ) : long

Get the max value of values in all buckets for the given HystrixRollingNumberEvent type. The HystrixRollingNumberEvent must be a "MaxUpdater" type (HystrixRollingNumberEvent.IsMaxUpdater() == true).

GetRollingSum ( HystrixRollingNumberEvent type ) : long

Get the sum of all buckets in the rolling counter for the given HystrixRollingNumberEvent type. The HystrixRollingNumberEvent must be a "Counter" type (HystrixRollingNumberEvent.IsCounter() == true).

GetValueOfLatestBucket ( HystrixRollingNumberEvent type ) : long

Get the value of the latest (current) bucket in the rolling counter for the given HystrixRollingNumberEvent type. The HystrixRollingNumberEvent must be a "Counter" type (HystrixRollingNumberEvent.IsCounter() == true).

GetValues ( HystrixRollingNumberEvent type ) : long[]

Get an array of values for all buckets in the rolling counter for the given HystrixRollingNumberEvent type. Index 0 is the oldest bucket. The HystrixRollingNumberEvent must be a "Counter" type (HystrixRollingNumberEvent.IsCounter() == true).

HystrixRollingNumber ( IHystrixProperty timeInMilliseconds, IHystrixProperty numberOfBuckets ) : System

Initializes a new instance of the HystrixRollingNumber class.

Increment ( HystrixRollingNumberEvent type ) : void

Increment the counter in the current bucket by one for the given HystrixRollingNumberEvent type.

Reset ( ) : void

Force a reset of all rolling counters (clear all buckets) so that statistics start being gathered from scratch. This does NOT reset the CumulativeSum values.

UpdateRollingMax ( HystrixRollingNumberEvent type, long value ) : void

Update a value and retain the max value.

Private Methods

Méthode 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.

HystrixRollingNumber ( ITime time, IHystrixProperty timeInMilliseconds, IHystrixProperty numberOfBuckets ) : System

Initializes a new instance of the HystrixRollingNumber class.

HystrixRollingNumber ( ITime time, int timeInMilliseconds, int numberOfBuckets ) : System

Initializes a new instance of the HystrixRollingNumber class. This constructor is used for unit testing to be able to inject mocked time measurement.

Method Details

Add() public méthode

Add to the counter in the current bucket for the given HystrixRollingNumberEvent type.
public Add ( HystrixRollingNumberEvent type, long value ) : void
type HystrixRollingNumberEvent Defining which counter to add to, must be a "Counter" type (HystrixRollingNumberEvent.IsCounter() == true).
value long Value to be added to the current bucket.
Résultat void

GetCumulativeSum() public méthode

Get the cumulative sum of all buckets ever since the application started without rolling for the given HystrixRollingNumberEvent type. See GetRollingSum(HystrixRollingNumberEvent) for the rolling sum.
public GetCumulativeSum ( HystrixRollingNumberEvent type ) : long
type HystrixRollingNumberEvent Must be a "Counter" type (HystrixRollingNumberEvent.IsCounter() == true).
Résultat long

GetRollingMaxValue() public méthode

Get the max value of values in all buckets for the given HystrixRollingNumberEvent type. The HystrixRollingNumberEvent must be a "MaxUpdater" type (HystrixRollingNumberEvent.IsMaxUpdater() == true).
public GetRollingMaxValue ( HystrixRollingNumberEvent type ) : long
type HystrixRollingNumberEvent HystrixRollingNumberEvent defining which "MaxUpdater" to retrieve values from
Résultat long

GetRollingSum() public méthode

Get the sum of all buckets in the rolling counter for the given HystrixRollingNumberEvent type. The HystrixRollingNumberEvent must be a "Counter" type (HystrixRollingNumberEvent.IsCounter() == true).
public GetRollingSum ( HystrixRollingNumberEvent type ) : long
type HystrixRollingNumberEvent defining which counter to retrieve values from
Résultat long

GetValueOfLatestBucket() public méthode

Get the value of the latest (current) bucket in the rolling counter for the given HystrixRollingNumberEvent type. The HystrixRollingNumberEvent must be a "Counter" type (HystrixRollingNumberEvent.IsCounter() == true).
public GetValueOfLatestBucket ( HystrixRollingNumberEvent type ) : long
type HystrixRollingNumberEvent HystrixRollingNumberEvent defining which counter to retrieve value from
Résultat long

GetValues() public méthode

Get an array of values for all buckets in the rolling counter for the given HystrixRollingNumberEvent type. Index 0 is the oldest bucket. The HystrixRollingNumberEvent must be a "Counter" type (HystrixRollingNumberEvent.IsCounter() == true).
public GetValues ( HystrixRollingNumberEvent type ) : long[]
type HystrixRollingNumberEvent HystrixRollingNumberEvent defining which counter to retrieve values from
Résultat long[]

HystrixRollingNumber() public méthode

Initializes a new instance of the HystrixRollingNumber class.
public HystrixRollingNumber ( IHystrixProperty timeInMilliseconds, IHystrixProperty numberOfBuckets ) : System
timeInMilliseconds IHystrixProperty The total time window to track.
numberOfBuckets IHystrixProperty The number of parts to break the time window.
Résultat System

Increment() public méthode

Increment the counter in the current bucket by one for the given HystrixRollingNumberEvent type.
public Increment ( HystrixRollingNumberEvent type ) : void
type HystrixRollingNumberEvent Defining which counter to increment, must be a "Counter" type (HystrixRollingNumberEvent.IsCounter() == true).
Résultat void

Reset() public méthode

Force a reset of all rolling counters (clear all buckets) so that statistics start being gathered from scratch. This does NOT reset the CumulativeSum values.
public Reset ( ) : void
Résultat void

UpdateRollingMax() public méthode

Update a value and retain the max value.
public UpdateRollingMax ( HystrixRollingNumberEvent type, long value ) : void
type HystrixRollingNumberEvent Defining which counter to update, must be a "MaxUpdater" type (HystrixRollingNumberEvent.IsMaxUpdater() == true).
value long Value to be updated to the current bucket
Résultat void