You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ni...@apache.org on 2022/03/03 15:50:04 UTC

[activemq-artemis] branch main updated: ARTEMIS-3522 Improve next fire time computation using double period

This is an automated email from the ASF dual-hosted git repository.

nigrofranz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git


The following commit(s) were added to refs/heads/main by this push:
     new a519164  ARTEMIS-3522 Improve next fire time computation using double period
     new 7effa48  This closes #3974
a519164 is described below

commit a51916447efc05c7e7ade68f035261b864d27503
Author: franz1981 <ni...@gmail.com>
AuthorDate: Thu Mar 3 16:46:28 2022 +0100

    ARTEMIS-3522 Improve next fire time computation using double period
---
 .../messages/perf/ProducerTargetRateLoadGenerator.java        | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/perf/ProducerTargetRateLoadGenerator.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/perf/ProducerTargetRateLoadGenerator.java
index 3310a02..63a3dd2 100644
--- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/perf/ProducerTargetRateLoadGenerator.java
+++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/perf/ProducerTargetRateLoadGenerator.java
@@ -16,7 +16,6 @@
  */
 package org.apache.activemq.artemis.cli.commands.messages.perf;
 
-import java.util.concurrent.TimeUnit;
 import java.util.function.BooleanSupplier;
 
 import io.netty.util.concurrent.OrderedEventExecutor;
@@ -24,7 +23,9 @@ import org.HdrHistogram.SingleWriterRecorder;
 
 public final class ProducerTargetRateLoadGenerator extends SkeletalProducerLoadGenerator {
 
-   private final long usPeriod;
+   private final double usPeriod;
+   private long startLoadMicros;
+   private long fireCount;
    private long fireTimeMicros;
    private boolean started;
 
@@ -39,7 +40,7 @@ public final class ProducerTargetRateLoadGenerator extends SkeletalProducerLoadG
                                           final SingleWriterRecorder waitLatencies) {
       super(producer, executor, timeProvider, keepOnSending, group, msgContent, sendCompletedLatencies, waitLatencies);
       this.fireTimeMicros = 0;
-      this.usPeriod = TimeUnit.NANOSECONDS.toMicros(nsPeriod);
+      this.usPeriod = nsPeriod / 1000d;
       this.started = false;
    }
 
@@ -51,6 +52,7 @@ public final class ProducerTargetRateLoadGenerator extends SkeletalProducerLoadG
       final long now = timeProvider.now();
       if (!started) {
          started = true;
+         startLoadMicros = now;
          fireTimeMicros = now;
       }
       if (!trySend(fireTimeMicros, now)) {
@@ -61,7 +63,8 @@ public final class ProducerTargetRateLoadGenerator extends SkeletalProducerLoadG
          stopLoad = true;
          return;
       }
-      fireTimeMicros += usPeriod;
+      fireCount++;
+      fireTimeMicros = startLoadMicros + (long) (fireCount * usPeriod);
       final long delay = fireTimeMicros - timeProvider.now();
       final long usToNextFireTime = Math.max(0, delay);
       asyncContinue(usToNextFireTime);