public class HystrixRollingNumber extends Object
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.
See UnitTest for usage and expected behavior examples.
Constructor and Description |
---|
HystrixRollingNumber(HystrixProperty<Integer> timeInMilliseconds,
HystrixProperty<Integer> numberOfBuckets)
Deprecated.
Please use
instead . These values are no longer allowed to
be updated at runtime. |
HystrixRollingNumber(int timeInMilliseconds,
int numberOfBuckets) |
Modifier and Type | Method and Description |
---|---|
void |
add(HystrixRollingNumberEvent type,
long value)
Add to the counter in the current bucket for the given
HystrixRollingNumberEvent type. |
long |
getCumulativeSum(HystrixRollingNumberEvent type)
Get the cumulative sum of all buckets ever since the JVM started without rolling for the given
HystrixRollingNumberEvent type. |
long |
getRollingMaxValue(HystrixRollingNumberEvent type)
Get the max value of values in all buckets for the given
HystrixRollingNumberEvent type. |
long |
getRollingSum(HystrixRollingNumberEvent type)
Get the sum of all buckets in the rolling counter for the given
HystrixRollingNumberEvent type. |
long |
getValueOfLatestBucket(HystrixRollingNumberEvent type)
Get the value of the latest (current) bucket in the rolling counter for the given
HystrixRollingNumberEvent type. |
long[] |
getValues(HystrixRollingNumberEvent type)
Get an array of values for all buckets in the rolling counter for the given
HystrixRollingNumberEvent type. |
void |
increment(HystrixRollingNumberEvent type)
Increment the counter in the current bucket by one for the given
HystrixRollingNumberEvent type. |
void |
reset()
Force a reset of all rolling counters (clear all buckets) so that statistics start being gathered from scratch.
|
void |
updateRollingMax(HystrixRollingNumberEvent type,
long value)
Update a value and retain the max value.
|
@Deprecated public HystrixRollingNumber(HystrixProperty<Integer> timeInMilliseconds, HystrixProperty<Integer> numberOfBuckets)
instead
. These values are no longer allowed to
be updated at runtime.timeInMilliseconds
- length of time to report metrics overnumberOfBuckets
- number of buckets to usepublic HystrixRollingNumber(int timeInMilliseconds, int numberOfBuckets)
public void increment(HystrixRollingNumberEvent type)
HystrixRollingNumberEvent
type.
The HystrixRollingNumberEvent
must be a "counter" type HystrixRollingNumberEvent.isCounter() == true
.
type
- HystrixRollingNumberEvent defining which counter to incrementpublic void add(HystrixRollingNumberEvent type, long value)
HystrixRollingNumberEvent
type.
The HystrixRollingNumberEvent
must be a "counter" type HystrixRollingNumberEvent.isCounter() == true
.
type
- HystrixRollingNumberEvent defining which counter to add tovalue
- long value to be added to the current bucketpublic void updateRollingMax(HystrixRollingNumberEvent type, long value)
The HystrixRollingNumberEvent
must be a "max updater" type HystrixRollingNumberEvent.isMaxUpdater() == true
.
type
- HystrixRollingNumberEvent defining which counter to retrieve values fromvalue
- long value to be given to the max updaterpublic void reset()
This does NOT reset the CumulativeSum values.
public long getCumulativeSum(HystrixRollingNumberEvent type)
HystrixRollingNumberEvent
type.
See getRollingSum(HystrixRollingNumberEvent)
for the rolling sum.
The HystrixRollingNumberEvent
must be a "counter" type HystrixRollingNumberEvent.isCounter() == true
.
type
- HystrixRollingNumberEvent defining which counter to retrieve values fromHystrixRollingNumberEvent
counter typepublic long getRollingSum(HystrixRollingNumberEvent type)
HystrixRollingNumberEvent
type.
The HystrixRollingNumberEvent
must be a "counter" type HystrixRollingNumberEvent.isCounter() == true
.
type
- HystrixRollingNumberEvent defining which counter to retrieve values fromHystrixRollingNumberEvent
counter typepublic long getValueOfLatestBucket(HystrixRollingNumberEvent type)
HystrixRollingNumberEvent
type.
The HystrixRollingNumberEvent
must be a "counter" type HystrixRollingNumberEvent.isCounter() == true
.
type
- HystrixRollingNumberEvent defining which counter to retrieve value fromHystrixRollingNumberEvent
counter typepublic long[] getValues(HystrixRollingNumberEvent type)
HystrixRollingNumberEvent
type.
Index 0 is the oldest bucket.
The HystrixRollingNumberEvent
must be a "counter" type HystrixRollingNumberEvent.isCounter() == true
.
type
- HystrixRollingNumberEvent defining which counter to retrieve values fromHystrixRollingNumberEvent
counter typepublic long getRollingMaxValue(HystrixRollingNumberEvent type)
HystrixRollingNumberEvent
type.
The HystrixRollingNumberEvent
must be a "max updater" type HystrixRollingNumberEvent.isMaxUpdater() == true
.
type
- HystrixRollingNumberEvent defining which "max updater" to retrieve values fromHystrixRollingNumberEvent
type during rolling windowCopyright © 2017. All Rights Reserved.