Class AdaptiveThrottler.TimeBasedAccumulator
java.lang.Object
io.grpc.rls.AdaptiveThrottler.TimeBasedAccumulator
- Enclosing class:
AdaptiveThrottler
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classHolds the data for each slot (amount and end timestamp). -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intThe current index into the slot array.private final longThe time interval this statistic is concerned with.private static final intThe number of slots.private final longThe number of nanoseconds in each slot.private final AtomicReferenceArray<AdaptiveThrottler.TimeBasedAccumulator.Slot> The array of slots.private final com.google.common.base.Ticker -
Constructor Summary
ConstructorsConstructorDescriptionTimeBasedAccumulator(long internalNanos, com.google.common.base.Ticker ticker) Interval constructor. -
Method Summary
Modifier and TypeMethodDescription(package private) longget(long now) Returns the count of the statistic using the specified time value as the current time.(package private) longReturns the interval used by this statistic.getSlot(long now) Gets the current slot.private longgetSlotEndTime(long time) Computes the end boundary since the last bucket can be partial size.(package private) voidincrement(long now) Increments the count of the statistic by the specified amount for the specified time.toString()
-
Field Details
-
NUM_SLOTS
private static final int NUM_SLOTSThe number of slots. This value determines the accuracy of the get() method to interval / NUM_SLOTS.- See Also:
-
slots
The array of slots. -
interval
private final long intervalThe time interval this statistic is concerned with. -
slotNanos
private final long slotNanosThe number of nanoseconds in each slot. -
currentIndex
private volatile int currentIndexThe current index into the slot array.currentIndexmay be safely read without synchronization, but all writes must be performed inside of asynchronized(this){}block. -
ticker
private final com.google.common.base.Ticker ticker
-
-
Constructor Details
-
TimeBasedAccumulator
TimeBasedAccumulator(long internalNanos, com.google.common.base.Ticker ticker) Interval constructor.- Parameters:
internalNanos- is the stat interval in nanoseconds- Throws:
IllegalArgumentException- if the supplied interval is too small to be effective
-
-
Method Details
-
getSlot
Gets the current slot. -
getSlotEndTime
private long getSlotEndTime(long time) Computes the end boundary since the last bucket can be partial size.- Parameters:
time- the time for which to find the nearest slot boundary- Returns:
- the nearest slot boundary in nanos
-
getInterval
long getInterval()Returns the interval used by this statistic.- Returns:
- the interval
-
increment
void increment(long now) Increments the count of the statistic by the specified amount for the specified time.- Parameters:
now- is the time used to increment the count
-
get
long get(long now) Returns the count of the statistic using the specified time value as the current time.- Parameters:
now- the current time- Returns:
- the statistic count
-
toString
-