Skip to content

Commit

Permalink
[pulsar-perf] Write histogram files for consume command (apache#12569)
Browse files Browse the repository at this point in the history
* [pulsar-perf] Write histogram files for consume command

* [pulsar-perf] Disable writing to histogram files by default

Most users don't use the histogram files and instead opt for sending
metrics to prometheus, etc, so there's no need to have this enabled by
default.

Instead, add a new --histogram-file parameter to pulsar-perf
produce/consume which, when specified, dumps the contents of the
internal histogram to the given filename.

Previous behaviour can be achieved with the following options:

  $ pulsar-perf produce --histogram-file perf-producer-$(date +%s).hgrm

* [pulsar-perf] Update docs with --histogram-file param

(cherry picked from commit 48de2e2)
  • Loading branch information
mfleming authored and nicoloboschi committed Dec 3, 2021
1 parent 9464408 commit 7474bbf
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import com.beust.jcommander.ParameterException;
import com.beust.jcommander.Parameters;
import java.io.FileInputStream;
import java.lang.management.BufferPoolMXBean;
import java.lang.management.ManagementFactory;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.nio.ByteBuffer;
import java.text.DecimalFormat;
import java.util.Collections;
Expand All @@ -38,6 +38,7 @@
import java.util.concurrent.atomic.LongAdder;

import org.HdrHistogram.Histogram;
import org.HdrHistogram.HistogramLogWriter;
import org.HdrHistogram.Recorder;
import org.apache.pulsar.client.api.ClientBuilder;
import org.apache.pulsar.client.api.Consumer;
Expand Down Expand Up @@ -181,6 +182,9 @@ static class Arguments {

@Parameter(names = {"-bw", "--busy-wait"}, description = "Enable Busy-Wait on the Pulsar client")
public boolean enableBusyWait = false;

@Parameter(names = { "--histogram-file" }, description = "HdrHistogram output file")
public String histogramFile = null;
}

public static void main(String[] args) throws Exception {
Expand Down Expand Up @@ -392,7 +396,19 @@ public static void main(String[] args) throws Exception {
long oldTime = System.nanoTime();

Histogram reportHistogram = null;
HistogramLogWriter histogramLogWriter = null;

if (arguments.histogramFile != null) {
String statsFileName = arguments.histogramFile;
log.info("Dumping latency stats to {}", statsFileName);

PrintStream histogramLog = new PrintStream(new FileOutputStream(statsFileName), false);
histogramLogWriter = new HistogramLogWriter(histogramLog);

// Some log header bits
histogramLogWriter.outputLogFormatVersion();
histogramLogWriter.outputLegend();
}

while (true) {
try {
Expand All @@ -417,6 +433,10 @@ public static void main(String[] args) throws Exception {
reportHistogram.getValueAtPercentile(99), reportHistogram.getValueAtPercentile(99.9),
reportHistogram.getValueAtPercentile(99.99), reportHistogram.getMaxValue());

if (histogramLogWriter != null) {
histogramLogWriter.outputIntervalHistogram(reportHistogram);
}

reportHistogram.reset();
oldTime = now;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,9 @@ static class Arguments {

@Parameter(names = {"-fc", "--format-class"}, description="Custom Formatter class name")
public String formatterClass = "org.apache.pulsar.testclient.DefaultMessageFormatter";

@Parameter(names = { "--histogram-file" }, description = "HdrHistogram output file")
public String histogramFile = null;
}

public static void main(String[] args) throws Exception {
Expand Down Expand Up @@ -429,16 +432,19 @@ public static void main(String[] args) throws Exception {
long oldTime = System.nanoTime();

Histogram reportHistogram = null;
HistogramLogWriter histogramLogWriter = null;

String statsFileName = "perf-producer-" + System.currentTimeMillis() + ".hgrm";
log.info("Dumping latency stats to {}", statsFileName);
if (arguments.histogramFile != null) {
String statsFileName = arguments.histogramFile;
log.info("Dumping latency stats to {}", statsFileName);

PrintStream histogramLog = new PrintStream(new FileOutputStream(statsFileName), false);
HistogramLogWriter histogramLogWriter = new HistogramLogWriter(histogramLog);
PrintStream histogramLog = new PrintStream(new FileOutputStream(statsFileName), false);
histogramLogWriter = new HistogramLogWriter(histogramLog);

// Some log header bits
histogramLogWriter.outputLogFormatVersion();
histogramLogWriter.outputLegend();
// Some log header bits
histogramLogWriter.outputLogFormatVersion();
histogramLogWriter.outputLegend();
}

while (true) {
try {
Expand Down Expand Up @@ -473,7 +479,10 @@ public static void main(String[] args) throws Exception {
dec.format(reportHistogram.getValueAtPercentile(99.99) / 1000.0),
dec.format(reportHistogram.getMaxValue() / 1000.0));

histogramLogWriter.outputIntervalHistogram(reportHistogram);
if (histogramLogWriter != null) {
histogramLogWriter.outputIntervalHistogram(reportHistogram);
}

reportHistogram.reset();

oldTime = now;
Expand Down
4 changes: 3 additions & 1 deletion site2/docs/performance-pulsar-perf.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ After the command is executed, the test data is continuously output on the Conso
19:54:44.336 [Thread-1] INFO org.apache.pulsar.testclient.PerformanceProducer - Aggregated latency stats --- Latency: mean: 3.383 ms - med: 3.293 - 95pct: 4.610 - 99pct: 5.059 - 99.9pct: 5.588 - 99.99pct: 5.837 - 99.999pct: 6.609 - Max: 6.609
```

From the above test data, you can get the throughput statistics and the write latency statistics. The aggregated statistics is printed when the Pulsar Perf is stopped. You can press **Ctrl**+**C** to stop the Pulsar Perf. After the Pulsar Perf is stopped, the [HdrHistogram](http://hdrhistogram.github.io/HdrHistogram/) formatted test result appears under your directory. The document looks like `perf-producer-1589370810837.hgrm`. You can also check the test result through [HdrHistogram Plotter](https://hdrhistogram.github.io/HdrHistogram/plotFiles.html). For details about how to check the test result through [HdrHistogram Plotter](https://hdrhistogram.github.io/HdrHistogram/plotFiles.html), see [HdrHistogram Plotter](#hdrhistogram-plotter).
From the above test data, you can get the throughput statistics and the write latency statistics. The aggregated statistics is printed when the Pulsar Perf is stopped. You can press **Ctrl**+**C** to stop the Pulsar Perf. If you specify a filename with the `--histogram-file` parameter, a file with the [HdrHistogram](http://hdrhistogram.github.io/HdrHistogram/) formatted test result appears under your directory after Pulsar Perf is stopped. You can also check the test result through [HdrHistogram Plotter](https://hdrhistogram.github.io/HdrHistogram/plotFiles.html). For details about how to check the test result through [HdrHistogram Plotter](https://hdrhistogram.github.io/HdrHistogram/plotFiles.html), see [HdrHistogram Plotter](#hdrhistogram-plotter).

### Configuration options for `pulsar-perf produce`

Expand All @@ -54,6 +54,7 @@ The following table lists configuration options available for the `pulsar-perf p
| encryption-key-value-file | Set the file which contains the public key used to encrypt the payload. | N/A |
| exit-on-failure | Configure whether to exit from the process on publish failure. | false |
| help | Configure the help message. | false |
| histogram-file | HdrHistogram output file | N/A |
| max-connections | Set the maximum number of TCP connections to a single broker. | 100 |
| max-outstanding | Set the maximum number of outstanding messages. | 1000 |
| max-outstanding-across-partitions | Set the maximum number of outstanding messages across partitions. | 50000 |
Expand Down Expand Up @@ -113,6 +114,7 @@ The following table lists configuration options available for the `pulsar-perf c
| encryption-key-name | Set the name of the public key used to encrypt the payload. | N/A |
| encryption-key-value-file | Set the file which contains the public key used to encrypt the payload. | N/A |
| help | Configure the help message. | false |
| histogram-file | HdrHistogram output file | N/A |
| max-connections | Set the maximum number of TCP connections to a single broker. | 100 |
| num-consumers | Set the number of consumers for each topic. | 1 |
| num-topic | Set the number of topics. | 1 |
Expand Down

0 comments on commit 7474bbf

Please sign in to comment.