Search in sources :

Example 1 with PoissonEventsArrival

use of com.linkedin.d2.backuprequests.PoissonEventsArrival 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 PoissonEventsArrival

use of com.linkedin.d2.backuprequests.PoissonEventsArrival 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 PoissonEventsArrival

use of com.linkedin.d2.backuprequests.PoissonEventsArrival 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 PoissonEventsArrival

use of com.linkedin.d2.backuprequests.PoissonEventsArrival 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 PoissonEventsArrival

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

the class TestBackupRequestsClient method testBackupRequestsRun.

// @Test - Disabled due to flakiness. See SI-3077 to track and resolve this.
public void testBackupRequestsRun() throws Exception {
    final AtomicBoolean shutDown = new AtomicBoolean(false);
    final AtomicLong completed = new AtomicLong(0);
    AtomicReference<ServiceProperties> serviceProperties = new AtomicReference<>();
    TestBackupRequestsStrategyStatsConsumer statsConsumer = new TestBackupRequestsStrategyStatsConsumer();
    serviceProperties.set(createServiceProperties(null));
    final BackupRequestsClient client = createClient(serviceProperties::get, statsConsumer, false);
    final URI uri = URI.create("d2://testService");
    Thread loadGenerator = new Thread(() -> {
        /*
       * Little's theorem: L = a * W
       * W = 10 ms in the test (not including hiccups).
       * We want L to be 100, so a = 100 / 15 = 6.6 events per millisecond
       */
        EventsArrival arrivals = new PoissonEventsArrival(6.6, TimeUnit.MILLISECONDS);
        long lastNano = System.nanoTime();
        while (!shutDown.get()) {
            long nextNano = lastNano + arrivals.nanosToNextEvent();
            try {
                waitUntil(nextNano);
            } catch (Exception e) {
                e.printStackTrace();
            }
            RestRequest restRequest = new RestRequestBuilder(uri).setEntity(CONTENT).build();
            RequestContext requestContext = new RequestContext();
            requestContext.putLocalAttr(R2Constants.OPERATION, "get");
            Set<URI> hosts = new HashSet<>();
            hosts.add(uri);
            requestContext.putLocalAttr("D2-Hint-ExcludedHosts", hosts);
            client.restRequest(restRequest, requestContext, new Callback<RestResponse>() {

                @Override
                public void onSuccess(RestResponse result) {
                    completed.incrementAndGet();
                }

                @Override
                public void onError(Throwable e) {
                }
            });
            lastNano = nextNano;
        }
    });
    loadGenerator.start();
    Thread.sleep(10000);
    serviceProperties.set(createServiceProperties(Arrays.asList(createBackupRequestsConfiguration(5, "get"))));
    long startTime = System.currentTimeMillis();
    while (statsConsumer.getLatencyWithBackup().size() < 1 && System.currentTimeMillis() - startTime < 30000) {
        Thread.sleep(10);
    }
    long endTime = System.currentTimeMillis();
    // this should disable backup requests
    serviceProperties.set(createServiceProperties(Arrays.asList(createBackupRequestsConfiguration(5, "batch_get"))));
    Thread.sleep((endTime - startTime) * 2);
    // initialize shutdown of load generator
    shutDown.set(true);
    // sum up histograms
    Histogram withoutBackup = new Histogram(LatencyMetric.LOWEST_DISCERNIBLE_VALUE, LatencyMetric.HIGHEST_TRACKABLE_VALUE, LatencyMetric.NUMBER_OF_SIGNIFICANT_VALUE_DIGITS);
    Histogram withBackup = new Histogram(LatencyMetric.LOWEST_DISCERNIBLE_VALUE, LatencyMetric.HIGHEST_TRACKABLE_VALUE, LatencyMetric.NUMBER_OF_SIGNIFICANT_VALUE_DIGITS);
    statsConsumer.getLatencyWithoutBackup().stream().forEach(h -> {
        withoutBackup.add(h);
    });
    statsConsumer.getLatencyWithBackup().stream().forEach(h -> {
        withBackup.add(h);
    });
    assertEquals(withoutBackup.getTotalCount(), withBackup.getTotalCount());
    double withoutBackup99 = withoutBackup.getValueAtPercentile(99);
    double withBackup99 = withBackup.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 : AbstractHistogram(org.HdrHistogram.AbstractHistogram) Histogram(org.HdrHistogram.Histogram) URI(java.net.URI) PoissonEventsArrival(com.linkedin.d2.backuprequests.PoissonEventsArrival) EventsArrival(com.linkedin.d2.backuprequests.EventsArrival) RequestContext(com.linkedin.r2.message.RequestContext) PoissonEventsArrival(com.linkedin.d2.backuprequests.PoissonEventsArrival) HashSet(java.util.HashSet) RestResponse(com.linkedin.r2.message.rest.RestResponse) AtomicReference(java.util.concurrent.atomic.AtomicReference) JsonParseException(com.fasterxml.jackson.core.JsonParseException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) IOException(java.io.IOException) ServiceUnavailableException(com.linkedin.d2.balancer.ServiceUnavailableException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicLong(java.util.concurrent.atomic.AtomicLong) ServiceProperties(com.linkedin.d2.balancer.properties.ServiceProperties) RestRequest(com.linkedin.r2.message.rest.RestRequest) RestRequestBuilder(com.linkedin.r2.message.rest.RestRequestBuilder)

Aggregations

BoundedCostBackupRequestsStrategy (com.linkedin.d2.backuprequests.BoundedCostBackupRequestsStrategy)4 Test (org.testng.annotations.Test)3 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 EventsArrival (com.linkedin.d2.backuprequests.EventsArrival)1 PoissonEventsArrival (com.linkedin.d2.backuprequests.PoissonEventsArrival)1 ServiceUnavailableException (com.linkedin.d2.balancer.ServiceUnavailableException)1 ServiceProperties (com.linkedin.d2.balancer.properties.ServiceProperties)1 RequestContext (com.linkedin.r2.message.RequestContext)1 RestRequest (com.linkedin.r2.message.rest.RestRequest)1 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)1 RestResponse (com.linkedin.r2.message.rest.RestResponse)1 IOException (java.io.IOException)1 URI (java.net.URI)1 HashSet (java.util.HashSet)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 AbstractHistogram (org.HdrHistogram.AbstractHistogram)1 Histogram (org.HdrHistogram.Histogram)1