Search in sources :

Example 1 with SlidingTimeWindowArrayReservoir

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);
}
Also used : Histogram(com.codahale.metrics.Histogram) Timer(com.codahale.metrics.Timer) Reservoir(com.codahale.metrics.Reservoir) SlidingTimeWindowArrayReservoir(com.codahale.metrics.SlidingTimeWindowArrayReservoir) RollingWindowTimerBuilder(com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.RollingWindowTimerBuilder) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 2 with SlidingTimeWindowArrayReservoir

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));
}
Also used : Histogram(com.codahale.metrics.Histogram) SlidingTimeWindowArrayReservoir(com.codahale.metrics.SlidingTimeWindowArrayReservoir) Test(org.junit.Test)

Example 3 with SlidingTimeWindowArrayReservoir

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);
}
Also used : Histogram(com.codahale.metrics.Histogram) RollingWindowHistogramBuilder(com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.RollingWindowHistogramBuilder) Reservoir(com.codahale.metrics.Reservoir) SlidingTimeWindowArrayReservoir(com.codahale.metrics.SlidingTimeWindowArrayReservoir) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Aggregations

Histogram (com.codahale.metrics.Histogram)3 SlidingTimeWindowArrayReservoir (com.codahale.metrics.SlidingTimeWindowArrayReservoir)3 Test (org.junit.Test)3 Reservoir (com.codahale.metrics.Reservoir)2 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)2 Timer (com.codahale.metrics.Timer)1 RollingWindowHistogramBuilder (com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.RollingWindowHistogramBuilder)1 RollingWindowTimerBuilder (com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.RollingWindowTimerBuilder)1