Class BatchSizer

java.lang.Object
me.ahoo.cosid.internal.BatchSizer

public final class BatchSizer extends Object
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

    Constructors
    Constructor
    Description
    BatchSizer(long step, long maxBatch, Duration lookahead)
    A sizer that starts at step.
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    The size of the next reservation.
    long
    The values the lookahead needs at the estimated rate.
    double
     
    long
    record(long values, long elapsedMillis)
    Records that values were used up in elapsedMillis.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • BatchSizer

      public BatchSizer(long step, long maxBatch, Duration lookahead)
      A sizer that starts at step.
      Parameters:
      step - the smallest reservation
      maxBatch - the largest reservation, a multiple of step
      lookahead - how long the values at hand should last
  • Method Details

    • batch

      public long batch()
      The size of the next reservation.
      Returns:
      between step and maxBatch, a multiple of step
    • 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 that values were used up in elapsedMillis.
      Parameters:
      values - the size of the range used up
      elapsedMillis - how long it lasted; less than a millisecond counts as one
      Returns:
      the previous batch size if the batch changed, otherwise -1