C# 클래스 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.

파일 보기 프로젝트 열기: Elders/Hystrix.NET 1 사용 예제들

Private Properties

프로퍼티 타입 설명
GetCurrentBucket Bucket
HystrixRollingNumber System
HystrixRollingNumber System

공개 메소드들

메소드 설명
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.

비공개 메소드들

메소드 설명
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.

메소드 상세

Add() 공개 메소드

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.
리턴 void

GetCumulativeSum() 공개 메소드

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).
리턴 long

GetRollingMaxValue() 공개 메소드

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
리턴 long

GetRollingSum() 공개 메소드

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
리턴 long

GetValueOfLatestBucket() 공개 메소드

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
리턴 long

GetValues() 공개 메소드

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
리턴 long[]

HystrixRollingNumber() 공개 메소드

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.
리턴 System

Increment() 공개 메소드

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).
리턴 void

Reset() 공개 메소드

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
리턴 void

UpdateRollingMax() 공개 메소드

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
리턴 void