sijie closed pull request #2338: Introduce warmup period in performance producer
URL: https://github.com/apache/incubator-pulsar/pull/2338
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerformanceProducer.java
b/pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerformanceProducer.java
index 0643fe754b..bfd4fbbbbf 100644
---
a/pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerformanceProducer.java
+++
b/pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerformanceProducer.java
@@ -136,6 +136,9 @@
"--test-duration" }, description = "Test duration in secs. If
0, it will keep publishing")
public long testTime = 0;
+ @Parameter(names = "--warmup-time", description = "Warm-up time in
seconds (Default: 1 sec)")
+ public double warmupTimeSeconds = 1.0;
+
@Parameter(names = {
"--use-tls" }, description = "Use TLS encryption on the
connection")
public boolean useTls;
@@ -212,8 +215,6 @@ public static void main(String[] args) throws Exception {
}
}
- arguments.testTime = TimeUnit.SECONDS.toMillis(arguments.testTime);
-
// Dump config variables
ObjectMapper m = new ObjectMapper();
ObjectWriter w = m.writerWithDefaultPrettyPrinter();
@@ -319,14 +320,16 @@ public void run() {
try {
RateLimiter rateLimiter =
RateLimiter.create(arguments.msgRate);
- long startTime = System.currentTimeMillis();
+ long startTime = System.nanoTime();
+ long warmupEndTime = startTime + (long)
(arguments.warmupTimeSeconds * 1e9);
+ long testEndTime = startTime + (long) (arguments.testTime *
1e9);
// Send messages on all topics/producers
long totalSent = 0;
while (true) {
for (Producer<byte[]> producer : producers) {
if (arguments.testTime > 0) {
- if (System.currentTimeMillis() - startTime >
arguments.testTime) {
+ if (System.nanoTime() > testEndTime) {
log.info("------------------- DONE
-----------------------");
printAggregatedStats();
isDone.set(true);
@@ -352,9 +355,12 @@ public void run() {
messagesSent.increment();
bytesSent.add(payloadData.length);
- long latencyMicros =
NANOSECONDS.toMicros(System.nanoTime() - sendTime);
- recorder.recordValue(latencyMicros);
- cumulativeRecorder.recordValue(latencyMicros);
+ long now = System.nanoTime();
+ if (now > warmupEndTime) {
+ long latencyMicros = NANOSECONDS.toMicros(now
- sendTime);
+ recorder.recordValue(latencyMicros);
+ cumulativeRecorder.recordValue(latencyMicros);
+ }
}).exceptionally(ex -> {
log.warn("Write error on message", ex);
System.exit(-1);
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services