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
  • Loading branch information
mfleming authored Nov 5, 2021
1 parent 8496afc commit 48de2e2
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import com.beust.jcommander.ParameterException;
import com.beust.jcommander.Parameters;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.nio.ByteBuffer;
import java.text.DecimalFormat;
import java.util.Collections;
Expand All @@ -36,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 @@ -185,6 +188,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 @@ -406,7 +412,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 @@ -431,6 +449,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 @@ -253,6 +253,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 @@ -436,16 +439,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 @@ -480,7 +486,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 Down Expand Up @@ -61,6 +61,7 @@ The following table lists configuration options available for the `pulsar-perf p
| format-class | Set the custom formatter class name. | org.apache.pulsar.testclient.DefaultMessageFormatter |
| format-payload | Configure whether to format %i as a message index in the stream from producer and/or %t as the timestamp nanoseconds. | 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 @@ -131,6 +132,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 |
| expire_time_incomplete_chunked_messages | Set the expiration time for incomplete chunk messages (in milliseconds). | 0 |
| max-connections | Set the maximum number of TCP connections to a single broker. | 100 |
| max_chunked_msg | Set the max pending chunk messages. | 0 |
Expand Down

0 comments on commit 48de2e2

Please sign in to comment.