def timeToNextArrival()

in src/main/scala/com/twitter/iago/util/SlowStartPoissonProcess.scala [68:89]


  def timeToNextArrival(): Duration = {
    if (!reachedFinalRate) {
      arrivals += 1
      if (arrivals >= 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 (arrivals >= nextStepPoint.toInt) {
          nextStepPoint += (currentArrivalsPerSecond / 1000.0) + (stepPerMilli / 2.0)
          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)
  }