| <!-- | |
| 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 | |
| regarding copyright ownership. The ASF licenses this file | |
| to you under the Apache License, Version 2.0 (the | |
| "License"); you may not use this file except in compliance | |
| with the License. You may obtain a copy of the License at | |
| http://www.apache.org/licenses/LICENSE-2.0 | |
| Unless required by applicable law or agreed to in writing, | |
| software distributed under the License is distributed on an | |
| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
| KIND, either express or implied. See the License for the | |
| specific language governing permissions and limitations | |
| under the License. | |
| --> | |
| # 8. Quality | |
| > Previous: [7. Public API](7-api.md). Next: [9. Classic API](9-classic-api.md). | |
| ## 1. Observability | |
| **Logs** go through `tracing`. Spans carry the identifiers that tie events together: the topic, the producer or | |
| consumer name, the subscription, and the connection's addresses. Segment ids appear in logs only, never in the | |
| API. | |
| **Metrics** are recorded through [nanometer](https://github.com/merlimat/nanometer): each loop has its own local | |
| handles, so recording costs no synchronization, and the exporter sums them. The application passes an | |
| OpenTelemetry `MeterProvider`, and the client depends only on the `opentelemetry` API crate. Metric names and | |
| attributes are the Java client's, so dashboards work for both. The Java instrumentation in `pulsar-client` | |
| defines, among others: | |
| - `pulsar.client.connection.opened`, `.closed` and `.failed`; | |
| - `pulsar.client.lookup.duration`; | |
| - `pulsar.client.producer.message.send.duration`, `pulsar.client.producer.message.pending.count`; | |
| - `pulsar.client.consumer.message.received.count`, `pulsar.client.consumer.message.ack`; | |
| - `pulsar.client.memory.buffer.usage`. | |
| The full list is taken from the Java sources when metrics are implemented. Metrics of state that spans loops, | |
| such as the client memory buffer, use nanometer's shared gauges. | |
| ## 2. Testing | |
| | Layer | What it covers | How | | |
| |---|---|---| | |
| | Unit | Routing, layout application, the producer's retire, park and hold logic, position vectors, ack tracking, batching and bucketing, MessageId and Checkpoint encoding. | Plain tests on the state machines ([2](2-architecture.md) §2). | | |
| | Simulated broker | Protocol flows and failures: handshakes, lookups and redirects, splits and merges in the middle of produce and consume, reassignments, mode flips, reconnects, timeouts. | `apache-pulsar-testkit`: a scripted broker built on the protocol crate's codec, over in-memory connections, on a controlled clock. Deterministic, with no sockets or sleeps. For scalable topics, `scalable::World` simulates a cluster (topics, layouts, segments, producers, and the admin's split, merge and terminate, with the 5.0.1 broker's ordering of receipts, closes and layout pushes), and `producer::Harness` drives the producer's state machine against it as the driver would. | | |
| | Driver | That the compio layer moves bytes and time correctly: concurrent reads and writes, plain and TLS, reconnects, coalescing, keepalive, the loops of the thread-safe client, the producer task, the memory limit, the three APIs. | The same simulated broker, and the simulated cluster, behind loopback sockets, in `apache-pulsar`'s own tests. Real time, so they wait for states with generous deadlines, never for fixed delays. | | |
| | Integration | The client against a real broker. | The released `apachepulsar/pulsar` image (5.0.1 today), with a proxy, TLS, token and mTLS authentication, started from the test harness with testcontainers (`crates/apache-pulsar/tests/integration`). Admin operations (a split during traffic, a partitioned topic, a namespace policy) go through `pulsar-admin` in the broker container, and the Java client there reads back what the Rust producer stored. `cargo test` skips them; they need Docker. A broker built from master (`./gradlew docker`) when a test needs an unreleased change. | | |
| | Cross-language | Same routing, and identifiers that move between SDKs. | Routing vectors and golden MessageId and Checkpoint bytes generated by the Java client, plus Java ⇄ Rust produce and consume tests. | | |
| ### 2.1 Porting the Java tests | |
| The scenarios of the Java V5 tests are ported, not their code: | |
| - `pulsar-client-v5/src/test`: about 190 tests, mostly unit tests over Java internals with mocks. They map to | |
| unit and simulated-broker tests. | |
| - About 500 tests elsewhere in `apache/pulsar` use the V5 API, mostly the `V5*Test` and `ScalableTopic*Test` | |
| classes in `pulsar-broker`. They map to integration tests. | |
| - The Pulsar Functions, proxy and SASL tests are out of scope. | |
| [`tests/PORTING.md`](../tests/PORTING.md) lists each Java test class with its Rust counterpart and status, so | |
| coverage can be tracked. Many broker tests trigger splits and merges, or look at broker state. Against a container, | |
| that needs the admin REST API, so the test harness gets a small admin client of its own ([1](1-scope.md) §5). | |
| ### 2.2 Conformance | |
| The spec's test guidance (*conformance* §5) becomes a named suite: routing vectors, a split or merge during | |
| active produce and consume, a broker failover, cumulative ack across segments, and checkpoint round trips across | |
| a layout change. It is written so that it could later grow into a suite every SDK runs. | |
| ## 3. Compatibility and versioning | |
| - **Crate versions:** 0.x until the API settles. 1.0 once the required core is complete and the API has been | |
| used in practice. | |
| - **Spec version:** each release states the spec version it conforms to (1.0 to start), and which optional | |
| capabilities it implements: in its [release notes](https://github.com/apache/pulsar-client-rust/releases), and for | |
| the current code in the README's Conformance section. | |
| - **Brokers:** Pulsar 5.0 or later ([1](1-scope.md) §3). | |
| - **Serialized identifiers:** MessageId and Checkpoint bytes stay readable by every later release | |
| (*stability* §4.3). The golden-byte tests guard that. | |
| ## 4. CI | |
| - Linux on io_uring, and Linux forced onto the polling driver, so that the fallback stays tested. | |
| - macOS. | |
| - Windows, build only at first. | |
| - `rustfmt`, `clippy` (with `await_holding_refcell_ref` denied), docs, and the minimum Rust version. | |
| - `cargo-deny` for licenses (ASF third-party policy) and advisories. | |
| - Apache RAT for the ASF license header on every file but those `.rat-excludes` lists. | |
| - Integration tests against the broker container. | |
| - 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 | |
| Releases follow the ASF process: a signed source release, a vote on dev@, and then publishing to crates.io from | |
| the voted source. Every source file carries the ASF license header, and the repository has `LICENSE` and | |
| `NOTICE` files. The steps, and the scripts in `build-support/` they use, are in [RELEASE.md](../RELEASE.md). | |
| ## 6. Performance | |
| Two harnesses measure the client, and a recorded baseline is what later rounds compare with. | |
| - **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`: 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, their reports every 10 seconds 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 | |
| Benchmark driver can follow once the API is stable. | |
| ### 6.1 Baseline | |
| Recorded on 2026-11-21, at M6, on an Apple M5 Pro (18 cores, 48 GiB) on mains power, macOS 26, with Rust 1.99 in | |
| release builds. Docker Desktop's VM (10 CPUs, 19.5 GiB) ran the broker, `apachepulsar/pulsar:5.0.1` standalone, and | |
| both clients, Java's on Corretto 25. One laptop for the broker and both clients: the two runs of each case agree within | |
| about a tenth, but earlier ones, on battery power, came out up to a half lower, so the end-to-end numbers compare the | |
| clients roughly. A regression shows first in the micro-benchmarks, whose intervals are within a few percent. | |
| **Micro-benchmarks**, on the host, one thread: | |
| | Benchmark | Time | Throughput | | |
| |---|---|---| | |
| | Producer, 100 B messages, batched | 255 ns a message | 3.9 M messages/s | | |
| | Producer, 1 KiB messages, batched | 285 ns a message | 3.5 M messages/s | | |
| | Producer, 100 B messages, unbatched | 1.00 µs a message | 1.0 M messages/s | | |
| | Producer, 1 KiB messages, unbatched | 0.98 µs a message | 1.0 M messages/s | | |
| | Consumer, decoding an uncompressed batch of 1000 messages | 43 µs a batch | 1.9 GiB/s | | |
| | Codec, on a batch of 1000 messages of JSON (87 KB) | Compress | Decompress and split | | |
| |---|---|---| | |
| | LZ4 | 2.5 GiB/s | 1.5 GiB/s | | |
| | Snappy | 2.5 GiB/s | 1.4 GiB/s | | |
| | ZSTD, level 3 | 1.5 GiB/s | 1.2 GiB/s | | |
| | ZLIB, default level | 130 MiB/s | 990 MiB/s | | |
| **End to end**, `tools/perf/baseline.sh`, twice, each cell giving both runs: 20 s at the highest rate each client | |
| reaches, 1 KiB messages of uppercase letters, batches of up to 1 ms, one segment, unless the run says otherwise. | |
| | Run | This client, msg/s | Java's, msg/s | | |
| |---|---|---| | |
| | Produce | 453k / 463k | 929k / 997k | | |
| | Produce, four segments | 409k / 420k | 892k / 945k | | |
| | Produce, 100 B | 659k / 659k | 2.01M / 2.04M | | |
| | Produce, 10 KiB | 99.7k / 99.7k | 90.1k / 103k | | |
| | Produce, without batching | 178k / 179k | 426k / 444k | | |
| | Produce, LZ4, near-empty entries | 531k / 539k | 1.89M / 1.89M | | |
| | Produce, ZSTD, near-empty entries | 564k / 583k | 1.61M / 1.52M | | |
| | Consume 4M messages, receiving and acknowledging each | 18.3k / 18.3k thread-safe, 331k / 336k local | 411k / 423k | | |
| | Latency at 10,000 msg/s, 60 s after 10 s of warm-up | p50 | p99 | p99.9 | Max | | |
| |---|---|---|---|---| | |
| | This client | 1.48 / 1.50 ms | 2.42 / 2.41 ms | 2.87 / 2.72 ms | 6.2 / 6.7 ms | | |
| | Java's | 1.62 / 1.62 ms | 2.75 / 2.77 ms | 2.99 / 3.69 ms | 11.9 / 9.6 ms | | |
| What it shows: | |
| - **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 | |
| acknowledging one message at a time gets 18k msg/s there, against 330k on the local client. | |
| - **The LZ4 and ZSTD runs send near-empty entries:** every message has the same payload, as `pulsar-perf`'s, so a batch | |
| compresses to almost nothing. The micro-benchmarks measure the codecs. | |
| - **Latencies at the highest rate aren't compared:** they are mostly each message's wait for room in the 64 MiB window, | |
| which this client fills and Java's doesn't. | |
| ## 7. Open questions | |
| 1. **The broker image:** build one per CI run from a pinned `apache/pulsar` commit, or use a published nightly | |
| image if one exists? | |
| 2. **Admin calls for tests:** which REST endpoints trigger splits and merges, and is any of that available from | |
| `pulsar-admin` alone? |