in src/main/scala/com/twitter/iago/util/InfiniteSteppedPoissonProcess.scala [89:121]
def timeToNextArrival(): Duration = {
if (!finishedWarmup) {
totalArrivals += 1
if (totalArrivals >= nextStepPoint.toInt) {
// Compute when to next update rate (numerically integrate number of arrivals over the next ms).
// Loops handles the case where step points increase more quickly than arrivals.
while (totalArrivals >= nextStepPoint.toInt) {
nextStepPoint += increaseStepPoint
currentArrivalsPerSecond += stepPerMilli
}
// clamp rate to final arrival rate and only update distribution if it has changed (by 1+ RPS)
val mean = 1000000000.0 / currentRate
if (dist.getMean != mean) {
dist = new ExponentialDistributionImpl(mean)
}
}
val nanosToNextArrival = dist.inverseCumulativeProbability(rand.nextDouble())
Duration(nanosToNextArrival.toLong, TimeUnit.NANOSECONDS)
} else {
val nanosToNextArrival = 1000000000.0 / currentArrivalsPerSecond
val nextArrival = Duration(nanosToNextArrival.toLong, TimeUnit.NANOSECONDS)
if (accumulatedDuration < stepDuration) {
accumulatedDuration += nextArrival
} else {
// Time to step up the rate again
accumulatedDuration = Duration.Zero
currentArrivalsPerSecond += stepRate
}
return nextArrival
}
}