HBASE-23245 : MutableHistogram constructor changes and provide HistogramImpl maxExpected as long (#787)
Signed-off-by: Andrew Purtell <apurtell@apache.org> Signed-off-by: Xu Cang <xucang@apache.org> Signed-off-by: Guangxu Cheng <gxcheng@apache.org>
This commit is contained in:
parent
da06aa7f1f
commit
9cc144e3c7
|
@ -42,10 +42,6 @@ public class MutableHistogram extends MutableMetric implements MetricHistogram {
|
|||
}
|
||||
|
||||
public MutableHistogram(String name, String description) {
|
||||
this(name, description, Integer.MAX_VALUE << 2);
|
||||
}
|
||||
|
||||
protected MutableHistogram(String name, String description, long maxExpected) {
|
||||
this.name = StringUtils.capitalize(name);
|
||||
this.desc = StringUtils.uncapitalize(description);
|
||||
this.histogram = new HistogramImpl();
|
||||
|
|
|
@ -36,11 +36,7 @@ public abstract class MutableRangeHistogram extends MutableHistogram implements
|
|||
}
|
||||
|
||||
public MutableRangeHistogram(String name, String description) {
|
||||
this(name, description, Integer.MAX_VALUE << 2);
|
||||
}
|
||||
|
||||
public MutableRangeHistogram(String name, String description, long expectedMax) {
|
||||
super(name, description, expectedMax);
|
||||
super(name, description);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.apache.yetus.audience.InterfaceAudience;
|
|||
*/
|
||||
@InterfaceAudience.Private
|
||||
public class MutableSizeHistogram extends MutableRangeHistogram {
|
||||
|
||||
private final static String RANGE_TYPE = "SizeRangeCount";
|
||||
private final static long[] RANGES = {10,100,1000,10000,100000,1000000,10000000,100000000};
|
||||
|
||||
|
@ -34,11 +35,7 @@ public class MutableSizeHistogram extends MutableRangeHistogram {
|
|||
}
|
||||
|
||||
public MutableSizeHistogram(String name, String description) {
|
||||
this(name, description, RANGES[RANGES.length-2]);
|
||||
}
|
||||
|
||||
public MutableSizeHistogram(String name, String description, long expectedMax) {
|
||||
super(name, description, expectedMax);
|
||||
super(name, description);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -35,11 +35,7 @@ public class MutableTimeHistogram extends MutableRangeHistogram {
|
|||
}
|
||||
|
||||
public MutableTimeHistogram(String name, String description) {
|
||||
this(name, description, RANGES[RANGES.length - 2]);
|
||||
}
|
||||
|
||||
public MutableTimeHistogram(String name, String description, long expectedMax) {
|
||||
super(name, description, expectedMax);
|
||||
super(name, description);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -36,7 +36,7 @@ public class HistogramImpl implements Histogram {
|
|||
private final CounterImpl counter;
|
||||
|
||||
public HistogramImpl() {
|
||||
this(Integer.MAX_VALUE << 2);
|
||||
this((long) Integer.MAX_VALUE << 2);
|
||||
}
|
||||
|
||||
public HistogramImpl(long maxExpected) {
|
||||
|
|
|
@ -63,19 +63,19 @@ public class TestHistogramImpl {
|
|||
Snapshot snapshot = histogram.snapshot();
|
||||
|
||||
assertEquals(100, snapshot.getCount());
|
||||
assertEquals(50, snapshot.getMedian());
|
||||
assertEquals(49, snapshot.getMedian());
|
||||
assertEquals(49, snapshot.getMean());
|
||||
assertEquals(0, snapshot.getMin());
|
||||
assertEquals(99, snapshot.getMax());
|
||||
assertEquals(25, snapshot.get25thPercentile());
|
||||
assertEquals(75, snapshot.get75thPercentile());
|
||||
assertEquals(90, snapshot.get90thPercentile());
|
||||
assertEquals(95, snapshot.get95thPercentile());
|
||||
assertEquals(98, snapshot.get98thPercentile());
|
||||
assertEquals(99, snapshot.get99thPercentile());
|
||||
assertEquals(99, snapshot.get999thPercentile());
|
||||
assertEquals(24, snapshot.get25thPercentile());
|
||||
assertEquals(74, snapshot.get75thPercentile());
|
||||
assertEquals(89, snapshot.get90thPercentile());
|
||||
assertEquals(94, snapshot.get95thPercentile());
|
||||
assertEquals(97, snapshot.get98thPercentile());
|
||||
assertEquals(98, snapshot.get99thPercentile());
|
||||
assertEquals(98, snapshot.get999thPercentile());
|
||||
|
||||
assertEquals(51, snapshot.getCountAtOrBelow(50));
|
||||
assertEquals(100, snapshot.getCountAtOrBelow(50));
|
||||
|
||||
// check that histogram is reset.
|
||||
assertEquals(100, histogram.getCount()); // count does not reset
|
||||
|
@ -98,5 +98,23 @@ public class TestHistogramImpl {
|
|||
assertEquals(198, snapshot.get98thPercentile());
|
||||
assertEquals(199, snapshot.get99thPercentile());
|
||||
assertEquals(199, snapshot.get999thPercentile());
|
||||
|
||||
IntStream.range(500, 1000).forEach(histogram::update);
|
||||
|
||||
snapshot = histogram.snapshot();
|
||||
|
||||
assertEquals(500, snapshot.getCount());
|
||||
assertEquals(749, snapshot.getMedian());
|
||||
assertEquals(749, snapshot.getMean());
|
||||
assertEquals(500, snapshot.getMin());
|
||||
assertEquals(999, snapshot.getMax());
|
||||
assertEquals(624, snapshot.get25thPercentile());
|
||||
assertEquals(874, snapshot.get75thPercentile());
|
||||
assertEquals(949, snapshot.get90thPercentile());
|
||||
assertEquals(974, snapshot.get95thPercentile());
|
||||
assertEquals(989, snapshot.get98thPercentile());
|
||||
assertEquals(994, snapshot.get99thPercentile());
|
||||
assertEquals(998, snapshot.get999thPercentile());
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue