Search in sources :

Example 1 with BoundedCostBackupRequestsStrategy

use of com.linkedin.d2.backuprequests.BoundedCostBackupRequestsStrategy in project rest.li by linkedin.

the class TestBoundedCostBackupRequestsStrategy method testMinBackupDelay.

@Test
public void testMinBackupDelay() {
    BoundedCostBackupRequestsStrategy strategy = new BoundedCostBackupRequestsStrategy(5, 64, 1024, 128, 100);
    BackupRequestsSimulator simulator = new BackupRequestsSimulator(new PoissonEventsArrival(200, TimeUnit.SECONDS), new GaussianResponseTimeDistribution(10, 50, 10, 99, TimeUnit.MILLISECONDS), strategy);
    simulator.simulate(ITERATIONS);
    assertEquals(simulator.getNumberOfBackupRequestsMade(), 0);
}
Also used : BoundedCostBackupRequestsStrategy(com.linkedin.d2.backuprequests.BoundedCostBackupRequestsStrategy) Test(org.testng.annotations.Test)

Example 2 with BoundedCostBackupRequestsStrategy

use of com.linkedin.d2.backuprequests.BoundedCostBackupRequestsStrategy in project rest.li by linkedin.

the class TestBoundedCostBackupRequestsStrategy method testLongTailEffectOfBackupRequests.

@Test
public void testLongTailEffectOfBackupRequests() {
    BoundedCostBackupRequestsStrategy strategy = new BoundedCostBackupRequestsStrategy(5, 64, 1024, 128, 0);
    ResponseTimeDistribution hiccupDistribution = new GaussianResponseTimeDistribution(500, 1000, 500, TimeUnit.MILLISECONDS);
    BackupRequestsSimulator simulator = new BackupRequestsSimulator(new PoissonEventsArrival(200, TimeUnit.SECONDS), new GaussianWithHiccupResponseTimeDistribution(2, 10, 5, TimeUnit.MILLISECONDS, hiccupDistribution, 0.02), strategy);
    simulator.simulate(ITERATIONS);
    double withoutBackup99 = simulator.getResponseTimeWithoutBackupRequestsHistogram().getValueAtPercentile(99);
    double withBackup99 = simulator.getResponseTimeWithBackupRequestsHistogram().getValueAtPercentile(99);
    assertTrue(withBackup99 * 10 < withoutBackup99, "99th percentile is expected to be improved 10x, with backup: " + withBackup99 / 1000000 + "ms, without backup: " + withoutBackup99 / 1000000 + "ms");
}
Also used : BoundedCostBackupRequestsStrategy(com.linkedin.d2.backuprequests.BoundedCostBackupRequestsStrategy) Test(org.testng.annotations.Test)

Example 3 with BoundedCostBackupRequestsStrategy

use of com.linkedin.d2.backuprequests.BoundedCostBackupRequestsStrategy in project rest.li by linkedin.

the class TestBoundedCostBackupRequestsStrategy method testNumberOfBackupRequestsMade.

public double testNumberOfBackupRequestsMade(int pct, int burstSize) {
    BoundedCostBackupRequestsStrategy strategy = new BoundedCostBackupRequestsStrategy(pct, burstSize, 1024, 128, 0);
    BackupRequestsSimulator simulator = new BackupRequestsSimulator(new PoissonEventsArrival(200, TimeUnit.SECONDS), new GaussianResponseTimeDistribution(20, 100, 50, TimeUnit.MILLISECONDS), strategy);
    simulator.simulate(ITERATIONS);
    return ((100d * simulator.getNumberOfBackupRequestsMade()) / ITERATIONS);
}
Also used : BoundedCostBackupRequestsStrategy(com.linkedin.d2.backuprequests.BoundedCostBackupRequestsStrategy)

Example 4 with BoundedCostBackupRequestsStrategy

use of com.linkedin.d2.backuprequests.BoundedCostBackupRequestsStrategy in project rest.li by linkedin.

the class TestBoundedCostBackupRequestsStrategy method testValuesOutOfRange.

@Test
public void testValuesOutOfRange() {
    BoundedCostBackupRequestsStrategy strategy = new BoundedCostBackupRequestsStrategy(5, 64, 1024, 128, 0);
    BackupRequestsSimulator simulator = new BackupRequestsSimulator(new PoissonEventsArrival(200, TimeUnit.SECONDS), new GaussianResponseTimeDistribution(BoundedCostBackupRequestsStrategy.HIGH, 2 * BoundedCostBackupRequestsStrategy.HIGH, BoundedCostBackupRequestsStrategy.HIGH, TimeUnit.NANOSECONDS), strategy);
    simulator.simulate(ITERATIONS);
    assertTrue(((100d * simulator.getNumberOfBackupRequestsMade()) / ITERATIONS) < 5 + EXPECTED_PRECISSION);
    assertTrue(strategy.getTimeUntilBackupRequestNano().get() >= BoundedCostBackupRequestsStrategy.HIGH);
}
Also used : BoundedCostBackupRequestsStrategy(com.linkedin.d2.backuprequests.BoundedCostBackupRequestsStrategy) Test(org.testng.annotations.Test)

Example 5 with BoundedCostBackupRequestsStrategy

use of com.linkedin.d2.backuprequests.BoundedCostBackupRequestsStrategy in project rest.li by linkedin.

the class TestBackupRequestsStrategyFactory method testBoundedCostBackupRequestsWithDefaultsDeser.

@Test
public void testBoundedCostBackupRequestsWithDefaultsDeser() throws IOException {
    BackupRequestsConfiguration brc = new BackupRequestsConfiguration();
    BoundedCostBackupRequests bcbr = new BoundedCostBackupRequests();
    bcbr.setCost(3);
    brc.setOperation("BATCH_GET");
    brc.setStrategy(BackupRequestsConfiguration.Strategy.create(bcbr));
    String json = new JacksonDataCodec().mapToString(brc.data());
    @SuppressWarnings("unchecked") Map<String, Object> map = JacksonUtil.getObjectMapper().readValue(json, Map.class);
    BackupRequestsStrategy strategy = BackupRequestsStrategyFactory.tryCreate(map);
    assertNotNull(strategy);
    assertTrue(strategy instanceof BoundedCostBackupRequestsStrategy);
    BoundedCostBackupRequestsStrategy boundedCostStrategy = (BoundedCostBackupRequestsStrategy) strategy;
    assertEquals(boundedCostStrategy.getHistoryLength(), (int) bcbr.getHistoryLength());
    assertEquals(boundedCostStrategy.getMinBackupDelayNano(), (long) bcbr.getMinBackupDelayMs() * 1000L * 1000L);
    assertEquals(boundedCostStrategy.getRequiredHistory(), (int) bcbr.getRequiredHistoryLength());
    assertEquals(boundedCostStrategy.getPercent(), (double) bcbr.getCost());
}
Also used : JacksonDataCodec(com.linkedin.data.codec.JacksonDataCodec) BackupRequestsConfiguration(com.linkedin.d2.BackupRequestsConfiguration) BoundedCostBackupRequests(com.linkedin.d2.BoundedCostBackupRequests) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)5 BoundedCostBackupRequestsStrategy (com.linkedin.d2.backuprequests.BoundedCostBackupRequestsStrategy)4 BackupRequestsConfiguration (com.linkedin.d2.BackupRequestsConfiguration)2 BoundedCostBackupRequests (com.linkedin.d2.BoundedCostBackupRequests)2 JacksonDataCodec (com.linkedin.data.codec.JacksonDataCodec)2