use of com.codahale.metrics.SlidingTimeWindowArrayReservoir in project riposte by Nike-Inc.
the class SignalFxEndpointMetricsHandlerTest method RollingWindowTimerBuilder_newMetric_creates_new_timer_with_SlidingTimeWindowArrayReservoir_with_expected_values.
@DataProvider(value = { "42 | DAYS", "123 | SECONDS", "999 | MILLISECONDS", "3 | HOURS" }, splitBy = "\\|")
@Test
public void RollingWindowTimerBuilder_newMetric_creates_new_timer_with_SlidingTimeWindowArrayReservoir_with_expected_values(long amount, TimeUnit timeUnit) {
// given
RollingWindowTimerBuilder rwtb = new RollingWindowTimerBuilder(amount, timeUnit);
// when
Timer timer = rwtb.newMetric();
// then
Histogram histogram = (Histogram) getInternalState(timer, "histogram");
Reservoir reservoir = (Reservoir) getInternalState(histogram, "reservoir");
assertThat(reservoir).isInstanceOf(SlidingTimeWindowArrayReservoir.class);
// The expected value here comes from logic in the SlidingTimeWindowArrayReservoir constructor.
assertThat(getInternalState(reservoir, "window")).isEqualTo(timeUnit.toNanos(amount) * 256);
}
use of com.codahale.metrics.SlidingTimeWindowArrayReservoir in project ambry by linkedin.
the class BlobStoreCompactorTest method testGetDesiredSpeedPerSecond.
/**
* Tests for {@link BlobStoreCompactor#getDesiredSpeedPerSecond(double, int)}.
* @throws Exception
*/
@Test
public void testGetDesiredSpeedPerSecond() throws Exception {
refreshState(false, true, false);
int storeCompactionOperationsBytesPerSec = 1000;
int storeCompactionMinOperationBytesPerSec = 500;
double storeCompactionOperationsAdjustK = 1.5;
int storeDiskIoReservoirTimeWindowMs = 200;
state.properties.put("store.compaction.operations.bytes.per.sec", Integer.toString(storeCompactionOperationsBytesPerSec));
state.properties.put("store.compaction.min.operations.bytes.per.sec", Integer.toString(storeCompactionMinOperationBytesPerSec));
state.properties.put("store.compaction.operations.adjust.k", Double.toString(storeCompactionOperationsAdjustK));
state.properties.put("store.disk.io.reservoir.time.window.ms", Integer.toString(storeDiskIoReservoirTimeWindowMs));
compactor = getCompactor(state.log, DISK_IO_SCHEDULER, null, false);
compactor.initialize(state.index);
int latencyThreshold = 20;
// Test getDesiredSpeedPerSecond
assertEquals("Incorrect speed", storeCompactionOperationsBytesPerSec, compactor.getDesiredSpeedPerSecond(latencyThreshold, latencyThreshold));
assertEquals("Incorrect speed", storeCompactionOperationsBytesPerSec, compactor.getDesiredSpeedPerSecond(latencyThreshold - 1, latencyThreshold));
int actualLatency = latencyThreshold * 2;
int expectedSpeed = (int) (storeCompactionMinOperationBytesPerSec + (storeCompactionOperationsBytesPerSec - storeCompactionMinOperationBytesPerSec) * latencyThreshold / actualLatency / storeCompactionOperationsAdjustK);
assertEquals("Incorrect speed", expectedSpeed, compactor.getDesiredSpeedPerSecond(latencyThreshold * 2, latencyThreshold));
// // Test histogram and getDesiredSpeedPerSecond
Histogram histogram = new Histogram(new SlidingTimeWindowArrayReservoir(1000, TimeUnit.MILLISECONDS));
double p95 = histogram.getSnapshot().get95thPercentile();
assertEquals("Histogram without data should return 0.0", 0.0, p95, 0.001);
assertEquals("Incorrect speed", storeCompactionOperationsBytesPerSec, compactor.getDesiredSpeedPerSecond(p95, latencyThreshold));
histogram.update(100);
p95 = histogram.getSnapshot().get95thPercentile();
assertEquals("Histogram without data should return 0.0", 100.0, p95, 0.001);
expectedSpeed = (int) (storeCompactionMinOperationBytesPerSec + (storeCompactionOperationsBytesPerSec - storeCompactionMinOperationBytesPerSec) * latencyThreshold / p95 / storeCompactionOperationsAdjustK);
assertEquals("Incorrect speed", expectedSpeed, compactor.getDesiredSpeedPerSecond(p95, latencyThreshold));
}
use of com.codahale.metrics.SlidingTimeWindowArrayReservoir in project riposte by Nike-Inc.
the class SignalFxEndpointMetricsHandlerTest method RollingWindowHistogramBuilder_newMetric_creates_new_histogram_with_SlidingTimeWindowArrayReservoir_with_expected_values.
@DataProvider(value = { "42 | DAYS", "123 | SECONDS", "999 | MILLISECONDS", "3 | HOURS" }, splitBy = "\\|")
@Test
public void RollingWindowHistogramBuilder_newMetric_creates_new_histogram_with_SlidingTimeWindowArrayReservoir_with_expected_values(long amount, TimeUnit timeUnit) {
// given
RollingWindowHistogramBuilder rwhb = new RollingWindowHistogramBuilder(amount, timeUnit);
// when
Histogram histogram = rwhb.newMetric();
// then
Reservoir reservoir = (Reservoir) getInternalState(histogram, "reservoir");
assertThat(reservoir).isInstanceOf(SlidingTimeWindowArrayReservoir.class);
// The expected value here comes from logic in the SlidingTimeWindowArrayReservoir constructor.
assertThat(getInternalState(reservoir, "window")).isEqualTo(timeUnit.toNanos(amount) * 256);
}
Aggregations