Package io.grpc.rls
Class AdaptiveThrottler.TimeBasedAccumulator
java.lang.Object
io.grpc.rls.AdaptiveThrottler.TimeBasedAccumulator
- Enclosing class:
AdaptiveThrottler
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
Holds the data for each slot (amount and end timestamp). -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int
The current index into the slot array.private final long
The time interval this statistic is concerned with.private static final int
The number of slots.private final long
The 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) long
get
(long now) Returns the count of the statistic using the specified time value as the current time.(package private) long
Returns the interval used by this statistic.getSlot
(long now) Gets the current slot.private long
getSlotEndTime
(long time) Computes the end boundary since the last bucket can be partial size.(package private) void
increment
(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.currentIndex
may 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
-