use of com.palantir.dialogue.TestResponse in project dialogue by palantir.
the class SimulationTest method server_side_rate_limits.
@SimulationCase
void server_side_rate_limits(Strategy strategy) {
double totalRateLimit = .1;
int numServers = 4;
int numClients = 2;
double perServerRateLimit = totalRateLimit / numServers;
servers = servers(IntStream.range(0, numServers).mapToObj(i -> {
Meter requestRate = new Meter(simulation.codahaleClock());
Function<SimulationServer, Response> responseFunc = _s -> {
if (requestRate.getOneMinuteRate() < perServerRateLimit) {
requestRate.mark();
return new TestResponse().code(200);
} else {
return new TestResponse().code(429);
}
};
return SimulationServer.builder().serverName("node" + i).simulation(simulation).handler(h -> h.response(responseFunc).responseTime(Duration.ofSeconds(200))).build();
}).toArray(SimulationServer[]::new));
st = strategy;
result = Benchmark.builder().simulation(simulation).requestsPerSecond(totalRateLimit).sendUntil(Duration.ofMinutes(25_000)).clients(numClients, _i -> strategy.getChannel(simulation, servers)).abortAfter(Duration.ofHours(1_000)).run();
}
Aggregations