java.lang.Object
me.ahoo.cosid.internal.BatchSizer
Sizes reservations by a time budget (04-segment.md ยง2):
min(maxBatch, roundUpToStep(rate * lookahead)), at
least step. The rate is estimated from how fast whole ranges are used up, smoothed so that one burst does
not size the next reservation alone. Not thread-safe: the generator calls it under its switch lock.-
Constructor Summary
ConstructorsConstructorDescriptionBatchSizer(long step, long maxBatch, Duration lookahead) A sizer that starts atstep. -
Method Summary
-
Constructor Details
-
BatchSizer
A sizer that starts atstep.- Parameters:
step- the smallest reservationmaxBatch- the largest reservation, a multiple ofsteplookahead- how long the values at hand should last
-
-
Method Details
-
batch
public long batch()The size of the next reservation.- Returns:
- between
stepandmaxBatch, a multiple ofstep
-
rate
public double rate() -
budget
public long budget()The values the lookahead needs at the estimated rate.- Returns:
rate * lookahead, 0 before the first estimate
-
record
public long record(long values, long elapsedMillis) Records thatvalueswere used up inelapsedMillis.- Parameters:
values- the size of the range used upelapsedMillis- how long it lasted; less than a millisecond counts as one- Returns:
- the previous batch size if the batch changed, otherwise
-1
-