From c8338dd3ac0229f5fd2cbb68dc95ede8f7879379 Mon Sep 17 00:00:00 2001 From: Dmitry Vyazelenko <696855+vyazelenko@users.noreply.github.com> Date: Fri, 9 Feb 2024 19:53:37 +0100 Subject: [PATCH] [Java] Automatically increase send interval to match the target message rate when calculating the batch size. --- .../benchmarks/remote/LoadTestRig.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/benchmarks-api/src/main/java/uk/co/real_logic/benchmarks/remote/LoadTestRig.java b/benchmarks-api/src/main/java/uk/co/real_logic/benchmarks/remote/LoadTestRig.java index a6be8dd7..50bac21b 100644 --- a/benchmarks-api/src/main/java/uk/co/real_logic/benchmarks/remote/LoadTestRig.java +++ b/benchmarks-api/src/main/java/uk/co/real_logic/benchmarks/remote/LoadTestRig.java @@ -175,8 +175,20 @@ long send(final int iterations, final int numberOfMessages) // The `sendIntervalNs` might be off if the division is not exact in which case more messages will be sent per // second than specified via `numberOfMessages`. However, this guarantees that the duration of the send // operation is bound by the number of iterations. - final long sendIntervalNs = Math.max(NANOS_PER_SECOND / numberOfMessages, configuration.messageSendDelayNs()); - final int burstSize = (int)Math.ceil((double)numberOfMessages / (int)(NANOS_PER_SECOND / sendIntervalNs)); + long sendIntervalNs = Math.max(NANOS_PER_SECOND / numberOfMessages, configuration.messageSendDelayNs()); + int burstSize = numberOfMessages / (int)(NANOS_PER_SECOND / sendIntervalNs); + while (burstSize * (int)(NANOS_PER_SECOND / sendIntervalNs) < numberOfMessages) + { + sendIntervalNs *= 10; + if (sendIntervalNs > NANOS_PER_SECOND) + { + sendIntervalNs /= 10; + burstSize++; + break; + } + burstSize = numberOfMessages / (int)(NANOS_PER_SECOND / sendIntervalNs); + } + final long totalNumberOfMessages = (long)iterations * numberOfMessages; final long startTimeNs = clock.nanoTime(); final long stopTimeNs = startTimeNs + (iterations * NANOS_PER_SECOND);