TengYao Chi created KAFKA-21603:
-----------------------------------
Summary: Producer sender busy-polls while a partition's head batch
is held back by the sequence checks in drain()
Key: KAFKA-21603
URL: https://issues.apache.org/jira/browse/KAFKA-21603
Project: Kafka
Issue Type: Bug
Components: clients, producer
Reporter: TengYao Chi
Assignee: TengYao Chi
When drain() refuses the head batch of a partition for sequencing reasons,
ready() has already reported the partition's leader as ready, because readiness
only looks at batch size, linger, back-off and the like.
Sender.sendProducerData() then sets pollTimeout to 0 because readyNodes is not
empty, so the sender loops through ready(), drain() and NetworkClient.poll(0)
without sending anything for as long as the partition stays held.
Two checks in drainBatchesForOneNode() do this, both only during a leader
failover and for at most request.timeout.ms:
# shouldStopDrainBatchesForPartition(): a retried batch at the head whose
sequence is not the first in-flight sequence (trunk today).
# The hold from KAFKA-18905 (wouldExceedBrokerDeduplicationWindow()): sending
one more batch would push the oldest in-flight batch out of the broker's
deduplication window.
Measured locally at 2000 records/s with request.timeout.ms=15000: during a 9 s
hold the producer JVM used about 0.3 cpu-s per second against 0.1 otherwise,
about 600k extra selector polls. Trunk shows the same for case 1 while a leader
is SIGSTOPped. Bounded to one partition and one request.timeout.ms, but a busy
loop.
Proposed fix: let partitionReady() recognise both conditions and treat the
partition as backing off, contributing retry.backoff.ms to
nextReadyCheckDelayMs instead of adding the leader to readyNodes. Plain
not-ready is not enough: with the old leader's connection black-holed nothing
wakes the selector, NetworkClient.poll() only caps its timeout at
request.timeout.ms, and the request timeout that releases the hold is detected
inside poll(), so the release could lag by up to another request.timeout.ms.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)