Created
February 13, 2013 19:59
-
-
Save stevegury/261b0a204cd0726f47ea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// $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 => | |
metrics.add(i) | |
ostrich.add(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