diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 055b00d..a56291b 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -59,13 +59,16 @@ jobs: # `cargo test` could assert. One added later stays out the same way, instead of arriving at 0% and failing # this job for a change that could not have caused the drop. # + # tools/perf is a default member, so that `cargo build --release` builds `pulsar-perf`, but it is a binary + # of the same kind: it is left out of the report instead. + # # The generated protobuf code is left out of the report: there is far more of it than code written by hand, # most of it for commands the client does not use yet, and the total would measure little else. - name: Run the tests under cargo-llvm-cov run: > cargo llvm-cov --locked --json --output-path target/coverage.json - --ignore-filename-regex '/apache-pulsar-protocol/src/proto/' + --ignore-filename-regex '/apache-pulsar-protocol/src/proto/|/tools/perf/' - name: Summarize id: summary run: python3 .github/scripts/coverage-summary.py target/coverage.json diff --git a/Cargo.lock b/Cargo.lock index a189096..981a0cf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2675,17 +2675,6 @@ version = "2.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" -[[package]] -name = "perf" -version = "0.1.0" -dependencies = [ - "apache-pulsar", - "clap", - "compio", - "futures-util", - "hdrhistogram", -] - [[package]] name = "pin-project" version = "1.2.0" @@ -2901,6 +2890,17 @@ dependencies = [ "prost", ] +[[package]] +name = "pulsar-perf" +version = "0.1.0" +dependencies = [ + "apache-pulsar", + "clap", + "compio", + "futures-util", + "hdrhistogram", +] + [[package]] name = "quad-rand" version = "0.2.3" diff --git a/Cargo.toml b/Cargo.toml index dd5459e..e9a0022 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,6 +30,7 @@ default-members = [ "crates/apache-pulsar", "crates/apache-pulsar-protocol", "crates/apache-pulsar-testkit", + "tools/perf", ] [workspace.package] diff --git a/docs/8-quality.md b/docs/8-quality.md index 0936548..fb9c5f6 100644 --- a/docs/8-quality.md +++ b/docs/8-quality.md @@ -71,10 +71,10 @@ a layout change. It is written so that it could later grow into a suite every SD - `rustfmt`, `clippy` (with `await_holding_refcell_ref` denied), docs, and the minimum Rust version. - `cargo-deny` for licenses (ASF third-party policy) and advisories. - Integration tests against the broker container. -- Test coverage, measured with `cargo llvm-cov` on a pinned compiler, without the generated protobuf code. The - job lists the lines and regions no test runs, such as the error branch of a `?`, and fails a pull request whose - line coverage is below its base's. A drop needs a test for what the change added, or a reason in the pull - request for leaving the line unreached. +- Test coverage, measured with `cargo llvm-cov` on a pinned compiler, without the generated protobuf code or + `tools/perf`. The job lists the lines and regions no test runs, such as the error branch of a `?`, and fails a pull + request whose line coverage is below its base's. A drop needs a test for what the change added, or a reason in the + pull request for leaving the line unreached. ## 5. Releases @@ -89,11 +89,12 @@ Two harnesses measure the client, and a recorded baseline is what later rounds c - **Micro-benchmarks**, with criterion: `cargo bench -p apache-pulsar-protocol`. The producer's state machine routes, batches, encodes and matches the receipts of 1000 keyed messages, sans IO, batched or not; each codec compresses a batch of 1000 small JSON messages, and the consumer decompresses it and splits it into its messages. -- **End to end**, `tools/perf`: `perf produce` and `perf consume`, the producer's and the Queue consumer's throughput - and latency against a broker. Its options, its payloads and its summary lines are those of Java's `pulsar-perf`, - which drives the V5 client for a `topic://` topic, so that the two compare line for line. `tools/perf/baseline.sh` - runs both, each in a container of its own on the broker's Docker network, against a standalone broker of its own for - each run, both bounded by a 64 MiB client memory limit, the only bound a V5 producer has. +- **End to end**, `tools/perf`: this client's `pulsar-perf`, which `cargo build --release` builds. `pulsar-perf produce` + and `pulsar-perf consume` measure the producer's and the Queue consumer's throughput and latency against a broker. + Their options, their payloads and their summary lines are those of Java's `pulsar-perf`, which drives the V5 client + for a `topic://` topic, so that the two compare line for line. `tools/perf/baseline.sh` runs both, each in a + container of its own on the broker's Docker network, against a standalone broker of its own for each run, both + bounded by a 64 MiB client memory limit, the only bound a V5 producer has. Still to measure: loop counts, with producers spread over the thread-safe client's loops, and pulsar-rs, which has no scalable topics, so `persistent://` topics through the migration bridge, from a harness on tokio. An OpenMessaging @@ -145,11 +146,11 @@ reaches, 1 KiB messages of uppercase letters, batches of up to 1 ms, one segment What it shows: -- **The client side is bound by its CPU, the producer and `perf` driving it.** In a separate 1 KiB run, sampled with - `docker stats`, this client used 150–180% of a core, its loop's thread and the one making the load, for about 500k - msg/s, and 100% on the local client, both on one thread, for about 400k. Java's used under one core for about 990k, - and the broker had room every time. The state machine takes under 0.3 µs of a message, the micro-benchmarks say, - out of about 3 µs of CPU in all, `perf`'s share included: the next round looks for where the rest goes. +- **The client side is bound by its CPU, the producer and `pulsar-perf` driving it.** In a separate 1 KiB run, sampled + with `docker stats`, this client used 150–180% of a core, its loop's thread and the one making the load, for about + 500k msg/s, and 100% on the local client, both on one thread, for about 400k. Java's used under one core for about + 990k, and the broker had room every time. The state machine takes under 0.3 µs of a message, the micro-benchmarks + say, out of about 3 µs of CPU in all, `pulsar-perf`'s share included: the next round looks for where the rest goes. - **Large messages are bound by the broker:** at 10 KiB both clients store about 1 GB/s. - **At a fixed rate, the latencies match**, this client's a little lower. - **The thread-safe consumer's receives and acks each cross to its loop's thread**, so a loop receiving and diff --git a/tools/perf/Cargo.toml b/tools/perf/Cargo.toml index 2bd0984..29876b7 100644 --- a/tools/perf/Cargo.toml +++ b/tools/perf/Cargo.toml @@ -16,8 +16,8 @@ # under the License. [package] -name = "perf" -description = "Throughput and latency of the producer and the Queue consumer against a broker, as pulsar-perf measures them" +name = "pulsar-perf" +description = "Throughput and latency of the producer and the Queue consumer against a broker, as Java's pulsar-perf does" version.workspace = true edition.workspace = true license.workspace = true diff --git a/tools/perf/baseline.sh b/tools/perf/baseline.sh index cfe7600..cfb1f3d 100755 --- a/tools/perf/baseline.sh +++ b/tools/perf/baseline.sh @@ -16,11 +16,11 @@ # specific language governing permissions and limitations # under the License. -# The performance baseline (docs/8-quality.md §6): this client's `perf` against Java's `pulsar-perf`, which drives the -# V5 client for a `topic://` topic. Each run has a standalone broker of its own, and its client runs in a container of -# its own on the broker's Docker network, so that both clients take the same path to the broker. Both are bounded by a -# 64 MiB client memory limit, the only bound a V5 producer has. `perf` drives the thread-safe client, with one event -# loop, from a thread of its own, as `pulsar-perf` sends from a thread of its own. +# The performance baseline (docs/8-quality.md §6): this client's `pulsar-perf` against Java's `pulsar-perf`, which +# drives the V5 client for a `topic://` topic. Each run has a standalone broker of its own, and its client runs in a +# container of its own on the broker's Docker network, so that both clients take the same path to the broker. Both are +# bounded by a 64 MiB client memory limit, the only bound a V5 producer has. This client's drives the thread-safe +# client, with one event loop, from a thread of its own, as Java's sends from a thread of its own. # # tools/perf/baseline.sh all the runs, each client in turn # tools/perf/baseline.sh latency the runs whose name holds `latency` @@ -44,10 +44,11 @@ cleanup() { } trap cleanup EXIT -# `perf` for Linux, built in the official Rust image, with its target and registry cached in volumes. +# This client's `pulsar-perf` for Linux, built in the official Rust image, with its target and registry cached in +# volumes. docker run --rm -v "$ROOT:/src:ro" -v apr-perf-target:/target -v apr-perf-registry:/usr/local/cargo/registry \ - -e CARGO_TARGET_DIR=/target -w /src "$RUST_IMAGE" cargo build --release --locked -p perf -docker run --rm -v apr-perf-target:/target -v "$BIN:/out" "$RUST_IMAGE" cp /target/release/perf /out/perf + -e CARGO_TARGET_DIR=/target -w /src "$RUST_IMAGE" cargo build --release --locked -p pulsar-perf +docker run --rm -v apr-perf-target:/target -v "$BIN:/out" "$RUST_IMAGE" cp /target/release/pulsar-perf /out/pulsar-perf docker network create "$NET" >/dev/null @@ -82,7 +83,7 @@ summary() { } rust() { - docker run --rm --network "$NET" -v "$BIN:/perf:ro" "$RUST_IMAGE" /perf/perf "$@" 2>&1 | summary + docker run --rm --network "$NET" -v "$BIN:/perf:ro" "$RUST_IMAGE" /perf/pulsar-perf "$@" 2>&1 | summary } java() { @@ -116,8 +117,8 @@ produce() { } # A Queue consumer of each client reading `$2` messages of 1 KiB from the earliest, on a broker of its own, which -# `perf` fills first. This client's twice: on the thread-safe client, whose receives and acks each cross to its loop's -# thread, and on the local client, on the thread receiving. +# this client's `pulsar-perf` fills first. This client's twice: on the thread-safe client, whose receives and acks +# each cross to its loop's thread, and on the local client, on the thread receiving. consume() { local name=$1 messages=$2 client topic [[ -z "$FILTER" || "$name" == *"$FILTER"* ]] || return 0 diff --git a/tools/perf/src/main.rs b/tools/perf/src/main.rs index ff8600d..659a31a 100644 --- a/tools/perf/src/main.rs +++ b/tools/perf/src/main.rs @@ -15,14 +15,15 @@ // specific language governing permissions and limitations // under the License. -//! `perf`: the producer's and the Queue consumer's throughput and latency against a broker (docs/8-quality.md §6). +//! `pulsar-perf`: the producer's and the Queue consumer's throughput and latency against a broker (docs/8-quality.md +//! §6). //! //! Its options and its summary lines are those of Java's `pulsar-perf produce` and `pulsar-perf consume`, so that the //! two clients compare line for line on the same broker: //! //! ```text -//! perf produce -u pulsar://localhost:6650 -s 1024 -m 1000000 -r 5000000 topic://public/default/perf -//! perf consume -u pulsar://localhost:6650 -m 1000000 topic://public/default/perf +//! pulsar-perf produce -u pulsar://localhost:6650 -s 1024 -m 1000000 -r 5000000 topic://public/default/perf +//! pulsar-perf consume -u pulsar://localhost:6650 -m 1000000 topic://public/default/perf //! ``` use std::pin::pin; @@ -42,7 +43,7 @@ use hdrhistogram::Histogram; const PER_MESSAGE_OVERHEAD: u64 = 1024; #[derive(Parser)] -#[command(about = "Throughput and latency of the producer and the Queue consumer, as pulsar-perf measures them")] +#[command(about = "Throughput and latency of the producer and the Queue consumer, as Java's pulsar-perf measures them")] struct Args { #[command(subcommand)] command: Command,