Permalink
Browse files

fix a bug in histogram where long shall be used instead of int for tr…

…acking each call time
  • Loading branch information...
1 parent ea2c4f0 commit 8b53cc0d5938afe5eae793dd44e02b129fd8a73c Lei Gao committed Mar 21, 2012
Showing with 18 additions and 18 deletions.
  1. +17 −17 src/java/voldemort/store/stats/Histogram.java
  2. +1 −1 src/java/voldemort/store/stats/RequestCounter.java
@@ -1,20 +1,20 @@
package voldemort.store.stats;
+import java.util.Arrays;
+
import voldemort.VoldemortException;
import voldemort.annotations.concurrency.Threadsafe;
-import java.util.Arrays;
-
/**
* A class for computing percentiles based on a histogram. Values are bucketed
* by a configurable bound (e.g., 0-1, 1-2, 2-3). When a value is inserted,
* perform a binary search to find the correct bucket.
- *
- *
+ *
+ *
*/
@Threadsafe
public class Histogram {
-
+
private final int nBuckets;
private final int step;
private final int[] buckets;
@@ -23,7 +23,7 @@
/**
* Initialize an empty histogram
- *
+ *
* @param nBuckets The number of buckets to use
* @param step The size of each bucket
*/
@@ -34,7 +34,7 @@ public Histogram(int nBuckets, int step) {
this.bounds = new int[nBuckets];
init();
}
-
+
protected void init() {
int bound = 0;
for(int i = 0; i < nBuckets; i++, bound += step) {
@@ -54,10 +54,10 @@ public synchronized void reset() {
/**
* Insert a value into the right bucket of the histogram. If the value is
* larger than any bound, insert into the last bucket
- *
+ *
* @param data The value to insert into the histogram
*/
- public synchronized void insert(int data) {
+ public synchronized void insert(long data) {
int index = findBucket(data);
if(index == -1) {
throw new VoldemortException(data + " can't be bucketed, is invalid!");
@@ -67,9 +67,9 @@ public synchronized void insert(int data) {
}
/**
- * Find the a value <em>n</em> such that the percentile falls within
- * [<em>n</em>, <em>n + step</em>)
- *
+ * Find the a value <em>n</em> such that the percentile falls within [
+ * <em>n</em>, <em>n + step</em>)
+ *
* @param quantile The percentile to find
* @return Lower bound associated with the percentile
*/
@@ -84,9 +84,9 @@ public synchronized int getQuantile(double quantile) {
}
return 0;
}
-
- private int findBucket(int needle) {
- int max = step * nBuckets;
+
+ private int findBucket(long needle) {
+ long max = step * nBuckets;
if(needle > max) {
return nBuckets - 1;
}
@@ -105,8 +105,8 @@ private int findBucket(int needle) {
}
return -1;
}
-
- private int compareToBucket(int bucket, int needle) {
+
+ private int compareToBucket(int bucket, long needle) {
int low = bounds[bucket];
int high = low + step;
if(low <= needle && high > needle) {
@@ -171,7 +171,7 @@ public void addRequest(long timeNS,
long numEmptyResponses,
long bytes,
long getAllAggregatedCount) {
- int timeMs = (int) timeNS / (int) Time.NS_PER_MS;
+ long timeMs = timeNS / Time.NS_PER_MS;
if(this.useHistogram) {
histogram.insert(timeMs);
maybeResetHistogram();

0 comments on commit 8b53cc0

Please sign in to comment.