Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
// $BIRDCAGE_HOME/bin/scala -i finagle/finagle-example
import com.twitter.ostrich.stats.Histogram
import com.twitter.common.stats.ApproximateHistogram
import scala.util.Random
val random = new Random
val metrics = new ApproximateHistogram
val ostrich = new Histogram()
val input = (1 to 10000) map { _ => random.nextInt(10000) }
input foreach { i =>
val op50 = ostrich.getPercentile(0.50)
val op90 = ostrich.getPercentile(0.90)
val op99 = ostrich.getPercentile(0.99)
val Array(mp50, mp90, mp99) = metrics.getQuantiles(Array(0.50, 0.90, 0.99))
val sortedInput = input.sorted
def p(q: Double) = sortedInput((q * input.size).toInt)
val p50 = p(0.5)
val p90 = p(0.90)
val p99 = p(0.99)
"p50:%d ostrich:%d metrics:%d".format(p50, op50, mp50)
"p90:%d ostrich:%d metrics:%d".format(p90, op90, mp90)
"p99:%d ostrich:%d metrics:%d".format(p99, op99, mp99)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment