Search in sources :

Example 1 with DEFAULT_ENDPOINT

use of com.palantir.dialogue.core.Benchmark.DEFAULT_ENDPOINT in project dialogue by palantir.

the class SimulationTest method server_side_rate_limits_with_sticky_clients_steady_vs_bursty_client.

@SimulationCase
void server_side_rate_limits_with_sticky_clients_steady_vs_bursty_client(Strategy strategy) {
    // 1 server
    // 2 types of clients sharing a DialogueChannel
    // - client that sends a request once a second
    // - client that burst sends 10k requests instantly
    // Assuming:
    // * server concurrency limit of 1
    // * 5ms to serve a request
    // 
    // Serving the bursty client by itself would take 50s. That is fine for that client, because it
    // is trying to do a lot. However, we should not make the slow-and-steady client wait 50s to send it's request.
    int numServers = 1;
    int concurrencyLimit = 1;
    Duration responseTime = Duration.ofMillis(5);
    Duration benchmarkDuration = Duration.ofMinutes(1);
    Duration timeBetweenSlowAndSteadyRequests = Duration.ofSeconds(1);
    long numSlowAndSteady = benchmarkDuration.toNanos() / timeBetweenSlowAndSteadyRequests.toNanos();
    assertThat(numSlowAndSteady).isEqualTo(60);
    Duration timeBetweenBurstRequests = Duration.ofNanos(50);
    long numBurst = 10_000;
    long totalNumRequests = numSlowAndSteady + numBurst;
    assertThat(totalNumRequests).isEqualTo(10060);
    servers = servers(IntStream.range(0, numServers).mapToObj(i -> SimulationServer.builder().serverName("node" + i).simulation(simulation).handler(h -> h.respond200UntilCapacity(429, concurrencyLimit).responseTime(responseTime)).build()).toArray(SimulationServer[]::new));
    Supplier<Channel> stickyChannelSupplier = strategy.getSticky2NonReloading(simulation, servers.get());
    Benchmark builder = Benchmark.builder().simulation(simulation);
    EndpointChannel slowAndSteadyChannel = builder.addEndpointChannel("slowAndSteady", DEFAULT_ENDPOINT, stickyChannelSupplier.get());
    EndpointChannel oneShotBurstChannel = builder.addEndpointChannel("oneShotBurst", DEFAULT_ENDPOINT, stickyChannelSupplier.get());
    Stream<ScheduledRequest> slowAndSteadyChannelRequests = builder.infiniteRequests(timeBetweenSlowAndSteadyRequests, () -> slowAndSteadyChannel).limit(numSlowAndSteady);
    Stream<ScheduledRequest> oneShotBurstChannelRequests = builder.infiniteRequests(timeBetweenBurstRequests, () -> oneShotBurstChannel).limit(numBurst);
    st = strategy;
    result = builder.mergeRequestStreams(slowAndSteadyChannelRequests, oneShotBurstChannelRequests).stopWhenNumReceived(totalNumRequests).abortAfter(benchmarkDuration.plus(Duration.ofMinutes(1))).run();
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Inherited(java.lang.annotation.Inherited) LoggerFactory(org.slf4j.LoggerFactory) Random(java.util.Random) AfterAll(org.junit.jupiter.api.AfterAll) Duration(java.time.Duration) Map(java.util.Map) Tracers(com.palantir.tracing.Tracers) Path(java.nio.file.Path) ExecutionMode(org.junit.jupiter.api.parallel.ExecutionMode) StandardOpenOption(java.nio.file.StandardOpenOption) Channel(com.palantir.dialogue.Channel) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) TestInfo(org.junit.jupiter.api.TestInfo) TestResponse(com.palantir.dialogue.TestResponse) List(java.util.List) Stream(java.util.stream.Stream) Optional(java.util.Optional) Response(com.palantir.dialogue.Response) IntStream(java.util.stream.IntStream) Tracer(com.palantir.tracing.Tracer) Stopwatch(com.google.common.base.Stopwatch) EnumSource(org.junit.jupiter.params.provider.EnumSource) Function(java.util.function.Function) Supplier(java.util.function.Supplier) Retention(java.lang.annotation.Retention) ArrayList(java.util.ArrayList) Meter(com.codahale.metrics.Meter) ScheduledRequest(com.palantir.dialogue.core.Benchmark.ScheduledRequest) Suppliers(com.google.common.base.Suppliers) Endpoint(com.palantir.dialogue.Endpoint) DEFAULT_ENDPOINT(com.palantir.dialogue.core.Benchmark.DEFAULT_ENDPOINT) Logger(org.slf4j.Logger) Files(java.nio.file.Files) XYChart(org.knowm.xchart.XYChart) Observability(com.palantir.tracing.Observability) IOException(java.io.IOException) HttpMethod(com.palantir.dialogue.HttpMethod) TimeUnit(java.util.concurrent.TimeUnit) EndpointChannel(com.palantir.dialogue.EndpointChannel) AfterEach(org.junit.jupiter.api.AfterEach) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ChronoUnit(java.time.temporal.ChronoUnit) Paths(java.nio.file.Paths) Comparator(java.util.Comparator) Execution(org.junit.jupiter.api.parallel.Execution) RetentionPolicy(java.lang.annotation.RetentionPolicy) ScheduledRequest(com.palantir.dialogue.core.Benchmark.ScheduledRequest) Channel(com.palantir.dialogue.Channel) EndpointChannel(com.palantir.dialogue.EndpointChannel) Duration(java.time.Duration) EndpointChannel(com.palantir.dialogue.EndpointChannel) Endpoint(com.palantir.dialogue.Endpoint)

Aggregations

Meter (com.codahale.metrics.Meter)1 Stopwatch (com.google.common.base.Stopwatch)1 Suppliers (com.google.common.base.Suppliers)1 Channel (com.palantir.dialogue.Channel)1 Endpoint (com.palantir.dialogue.Endpoint)1 EndpointChannel (com.palantir.dialogue.EndpointChannel)1 HttpMethod (com.palantir.dialogue.HttpMethod)1 Response (com.palantir.dialogue.Response)1 TestResponse (com.palantir.dialogue.TestResponse)1 DEFAULT_ENDPOINT (com.palantir.dialogue.core.Benchmark.DEFAULT_ENDPOINT)1 ScheduledRequest (com.palantir.dialogue.core.Benchmark.ScheduledRequest)1 Observability (com.palantir.tracing.Observability)1 Tracer (com.palantir.tracing.Tracer)1 Tracers (com.palantir.tracing.Tracers)1 IOException (java.io.IOException)1 Inherited (java.lang.annotation.Inherited)1 Retention (java.lang.annotation.Retention)1 RetentionPolicy (java.lang.annotation.RetentionPolicy)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Files (java.nio.file.Files)1