frankvicky commented on PR #23663: URL: https://github.com/apache/kafka/pull/23663#issuecomment-6779024271
@chia7712 I have let claude setup the benchmark and here is the report: **TL;DR** `kafka-producer-perf-test` against a local 3-broker cluster, PR vs baseline, only the client jar swapped: **no difference unless the old leader's acks are lost. Then the PR trades one wait of `request.timeout.ms` for not failing records that are in the log.** | scenario | measured | PR | baseline | |---|---|---|---| | Clean leader change (old leader answers) | stall per change | about 1 s | about 1 s | | | failed records | 0 | 0 | | Leader stops answering (SIGSTOP) | stall on the partition | 15 s | 15 s | | | new batches held back | 5.8 to 7.3 s | 0 | | | failed records | 0 | 0 | | Acks lost, old leader alive (the bug this PR fixes) | stall on the partition | 15 s, once | 6 s, then 45 s more | | | new batches held back | 7.8 to 9.0 s | 0 | | | produce requests rejected with OOOSN | 0 | 54 to 57 | | | records reported failed although in the log | 0 | 24 to 28 | | Steady state, 300k rec/s, 1 partition | avg / p99 latency | 1.8 / 15 ms | 1.8 / 16 ms | | | producer cpu per 1M records | 1.9 s | 1.9 s | - New batches are held back for at most `request.timeout.ms` minus the time the leader change takes: 6 to 9 s here with 15 s, about 21 to 24 s with the default 30 s, 0 on a clean leader change. Purgatory does not enter. - Costs: the sender spins with `poll(0)` while a partition is held (about 0.2 core, trunk does the same behind `firstInFlightSequence`), and the hold uses up `delivery.timeout.ms` budget (no issue with the defaults, see details). <details> <summary>Details: how the hold behaves and what it costs</summary> How long new batches are held back: from the moment the client learns the new leader until the stuck requests hit `request.timeout.ms`, so at most `request.timeout.ms` minus the time the leader change takes. Here that was 15 s minus 6 to 9 s; with the default 30 s it would be about 21 to 24 s. It does not depend on purgatory: a live old leader fails its pending produces with `NOT_LEADER_OR_FOLLOWER` as soon as it steps down (`completeDelayedOperationsWhenNotPartitionLeader`), so on a clean change the hold is 0. It only engages while the old leader's responses never arrive. What the hold buys: with lost acks, the baseline resumes the partition 6 s after the fault, but when the 5 stuck batches time out and are retried, the new leader rejects them with `OUT_OF_ORDER_SEQUENCE_NUMBER` because more than 5 newer batches are appended by then. The client retries them until `delivery.timeout.ms`, the partition is blocked for those 45 s, and the 5 batches are reported failed although every record is in the log (end offsets add up exactly to the records sent). The PR waits once, the retries are answered as duplicates, nothing fails. Two costs of the hold. While a partition is held, `ready()` still reports it as sendable but `drain()` skips it, so the sender loops with `poll(0)` for the duration of the hold, about 0.2 core here (producer cpu 0.3 vs 0.1 cpu-s/s, 600k extra selector polls in 9 s); trunk does the same today while it retries behind the `firstInFlightSequence` check, in the SIGSTOP scenario both clients show about 500k polls per run. And the hold eats into `delivery.timeout.ms`: with `delivery.timeout.ms` set equal to `request.timeout.ms` the first held batch expired in flight right after it was finally sent (173 records failed although written, against 24 on the baseline); with the defaults there is 90 s of slack. </details> <details> <summary>Details: setup and per-run numbers</summary> Local KRaft, 1 controller + 3 brokers with default config, topics RF 3 / min.insync.replicas 2. Producer: 100-byte records, `acks=all`, `enable.idempotence=true`, `linger.ms=0`, `max.in.flight.requests.per.connection=5`, `request.timeout.ms=15000`, `delivery.timeout.ms=60000`, `metadata.max.age.ms=1000`. Failure scenarios: 3 partitions with one leader per broker, 2000 rec/s, times from the producer DEBUG log in seconds after the fault. Leader stops answering: SIGSTOP the leader of p0 for 20 s; the controller fences it after about 9 s. | run | learns new leader | first send to it | hold | first successful produce | rejected with OOOSN | |---|---|---|---|---|---| | 1 PR | 8.95 | 15.01 | 6.06 | 15.01 | 0 | | 1 baseline | 8.79 | 8.80 | 0.01 | 15.01 | 5 | | 2 PR | 9.31 | 15.09 | 5.78 | 15.10 | 0 | | 2 baseline | 8.69 | 8.70 | 0.00 | 15.10 | 5 | | 3 PR | 7.81 | 15.09 | 7.28 | 15.10 | 0 | | 3 baseline | 7.80 | 7.80 | 0.00 | 15.01 | 5 | Acks lost, old leader alive: a TCP proxy in front of the leader of p0 discards everything the broker sends to the client (the broker still appends and replicates), then p0's leadership is moved to another broker with a preferred election while the old leader stays up. | run | learns new leader | first send to it | hold | p0 blocked | rejected with OOOSN | records reported failed | |---|---|---|---|---|---|---| | 1 PR | 6.05 | 15.00 | 8.96 | 0 to 15.0 | 0 | 0 | | 1 baseline | 6.40 | 6.40 | 0 | 0 to 6.5, 15.0 to 60.0 | 56 | 24 | | 2 PR | 6.21 | 15.00 | 8.79 | 0 to 15.0 | 0 | 0 | | 2 baseline | 6.32 | 6.32 | 0 | 0 to 6.3, 15.0 to 60.0 | 57 | 28 | | 3 PR | 7.22 | 15.00 | 7.78 | 0 to 15.0 | 0 | 0 | | 3 baseline | 6.36 | 6.36 | 0 | 0 to 6.4, 14.8 to 60.0 | 54 | 24 | Variants, one pair each, to exercise the rest of the bookkeeping: `max.in.flight.requests.per.connection=3` (3 stuck, the PR sent exactly 2 more batches to the new leader and then held until the timeout; 0 failed vs 15 written-but-failed on the baseline); `delivery.timeout.ms=15000` (stuck batches expire under the hold, 3 epoch bumps, then clean, see the cost above); gzip with `max.message.bytes` = `batch.size` on a mixed-compressibility payload at 6000 rec/s (384 batch splits, 330 of them during and after the hold; hold released at +15.00, 0 failed, vs 65 written-but-failed and a block until +60 on the baseline). Steady state at 300k rec/s on 1 partition, 3 runs per client, alternating, PR vs merge-base: avg latency 1.73 to 1.87 ms vs 1.67 to 2.10 ms, p99 13 to 17 vs 13 to 21 ms, batch size 10.7 to 11.1 KB vs 10.7 to 11.3 KB, cpu 1.74 to 1.95 vs 1.86 to 1.96 s per million records. Unlimited-rate runs on this machine swing by 2 to 3x between runs of the same jar, so they are not reported. </details> -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
