Skip to content

Commit

Permalink
[Java] Automatically increase send interval to match the target messa…
Browse files Browse the repository at this point in the history
…ge rate when calculating the batch size.
  • Loading branch information
vyazelenko committed Feb 9, 2024
1 parent 1553b9e commit c8338dd
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c8338dd

Please sign in to comment.