Permalink
Browse files

initial integration of histogram into StoreStats

  • Loading branch information...
1 parent 2231cb5 commit 5513200f404a37ecd10911a4b44a59474d2ef218 @afeinberg afeinberg committed Feb 17, 2012
View
32 src/java/voldemort/store/stats/RequestCounter.java
@@ -16,6 +16,9 @@
private final AtomicReference<Accumulator> values;
private final int durationMS;
private final Time time;
+ private final Histogram histogram;
+ private volatile int q95LatencyMs;
+ private volatile int q99LatencyMs;
/**
* @param durationMS specifies for how long you want to maintain this
@@ -32,6 +35,9 @@ public RequestCounter(int durationMS) {
this.time = time;
this.values = new AtomicReference<Accumulator>(new Accumulator());
this.durationMS = durationMS;
+ this.histogram = new Histogram(15000, 1);
+ this.q95LatencyMs = 0;
+ this.q99LatencyMs = 0;
}
public long getCount() {
@@ -84,6 +90,19 @@ public long getMaxLatencyInMs() {
return getValidAccumulator().maxLatencyNS / Time.NS_PER_MS;
}
+ private void maybeResetHistogram() {
+ Accumulator accum = values.get();
+ long now = time.getMilliseconds();
+ if(now - accum.startTimeMS <= durationMS) {
+ // Reset the histogram
+ synchronized(histogram) {
+ q95LatencyMs = histogram.getQuantile(0.95);
+ q99LatencyMs = histogram.getQuantile(0.99);
+ histogram.reset();
+ }
+ }
+ }
+
private Accumulator getValidAccumulator() {
Accumulator accum = values.get();
@@ -131,6 +150,11 @@ public void addRequest(long timeNS) {
* @param getAllAggregatedCount Total number of keys returned for getAll calls
*/
public void addRequest(long timeNS, long numEmptyResponses, long bytes, long getAllAggregatedCount) {
+ synchronized(histogram) {
+ int timeMs = (int) timeNS / (int) Time.NS_PER_MS;
+ histogram.insert(timeMs);
+ }
+ maybeResetHistogram();
for(int i = 0; i < 3; i++) {
Accumulator oldv = getValidAccumulator();
Accumulator newv = new Accumulator(oldv.startTimeMS,
@@ -175,6 +199,14 @@ public long getGetAllAggregatedCount() {
return getValidAccumulator().getAllAggregatedCount;
}
+ public int getQ95LatencyMs() {
+ return q95LatencyMs;
+ }
+
+ public int getQ99LatencyMs() {
+ return q99LatencyMs;
+ }
+
private class Accumulator {
final long startTimeMS;
View
8 src/java/voldemort/store/stats/StoreStats.java
@@ -100,6 +100,14 @@ public long getMaxLatencyInMs(Tracked op) {
return counters.get(op).getMaxLatencyInMs();
}
+ public long getQ95LatencyInMs(Tracked op) {
+ return counters.get(op).getQ95LatencyMs();
+ }
+
+ public long getQ99LatencyInMs(Tracked op) {
+ return counters.get(op).getQ99LatencyMs();
+ }
+
public Map<Tracked, RequestCounter> getCounters() {
return Collections.unmodifiableMap(counters);
}
View
40 src/java/voldemort/store/stats/StoreStatsJmx.java
@@ -172,6 +172,46 @@ public long getMaxDeleteLatency() {
return stats.getMaxLatencyInMs(Tracked.DELETE);
}
+ @JmxGetter(name = "q95PutLatencyInMs", description="")
+ public long getQ95PutLatency() {
+ return stats.getQ95LatencyInMs(Tracked.PUT);
+ }
+
+ @JmxGetter(name = "q95GetLatencyInMs", description="")
+ public long getQ95GetLatency() {
+ return stats.getQ95LatencyInMs(Tracked.GET);
+ }
+
+ @JmxGetter(name = "q95GetAllLatencyInMs", description="")
+ public long getQ95GetAllLatency() {
+ return stats.getQ95LatencyInMs(Tracked.GET_ALL);
+ }
+
+ @JmxGetter(name = "q95DeleteLatencyInMs", description="")
+ public long getQ95DeleteLatency() {
+ return stats.getQ95LatencyInMs(Tracked.DELETE);
+ }
+
+ @JmxGetter(name = "q99PutLatencyInMs", description="")
+ public long getQ99PutLatency() {
+ return stats.getQ99LatencyInMs(Tracked.PUT);
+ }
+
+ @JmxGetter(name = "q99GetLatencyInMs", description="")
+ public long getQ99GetLatency() {
+ return stats.getQ99LatencyInMs(Tracked.GET);
+ }
+
+ @JmxGetter(name = "q99GetAllLatencyInMs", description="")
+ public long getQ99GetAllLatency() {
+ return stats.getQ99LatencyInMs(Tracked.GET_ALL);
+ }
+
+ @JmxGetter(name = "q99DeleteLatencyInMs", description="")
+ public long getQ99DeleteLatency() {
+ return stats.getQ99LatencyInMs(Tracked.DELETE);
+ }
+
@JmxGetter(name = "maxPutSizeInBytes", description = "Maximum size of value returned in bytes by PUT.")
public long getMaxPutSizeInBytes() {
return stats.getMaxSizeInBytes(Tracked.PUT);

0 comments on commit 5513200

Please sign in to comment.