Symptom
Producers report rising request-latency-avg, or end-to-end latency grows while throughput is flat. Some clients hit TimeoutException. Broker CPU looks moderate, so nothing obvious is wrong.
You don't need to guess. Every broker request is timed in phases, and the phase that grew tells you which part of the broker is the bottleneck. Run through this checklist on the broker that leads the slow partitions, not on a cluster average.
Read the request phases
Each request type (Produce, FetchConsumer, FetchFollower, and others) exposes these timers under kafka.network:type=RequestMetrics,name=<metric>,request=<type>:
| Metric | Phase | High value usually means |
|---|---|---|
RequestQueueTimeMs | Waiting for a free I/O (request handler) thread | I/O threads saturated |
LocalTimeMs | Leader doing the work: log append or read | Disk, lock contention, recompression, down-conversion |
RemoteTimeMs | Waiting on something else: followers for acks=all, long-poll for fetch | Slow followers, or normal fetch long-poll |
ThrottleTimeMs | Held back by a quota | Client quota hit |
ResponseQueueTimeMs | Waiting for a network thread to pick up the response | Network threads saturated |
ResponseSendTimeMs | Writing the response to the socket | Slow client, network, TLS cost |
TotalTimeMs | Sum of the above | Starting point only |
Pull the 99th percentiles with JmxTool. The class moved in Kafka 3.5 from kafka.tools.JmxTool to org.apache.kafka.tools.JmxTool; use the one your build ships.
JMX=service:jmx:rmi:///jndi/rmi://broker1:9999/jmxrmi
for m in TotalTimeMs RequestQueueTimeMs LocalTimeMs RemoteTimeMs ResponseQueueTimeMs ResponseSendTimeMs; do
echo "== $m"
timeout 12 bin/kafka-run-class.sh org.apache.kafka.tools.JmxTool \
--jmx-url "$JMX" \
--object-name "kafka.network:type=RequestMetrics,name=$m,request=Produce" \
--attributes 99thPercentile,Mean \
--reporting-interval 5000
done
If you scrape with the Prometheus JMX exporter, the same MBeans appear under names derived from your exporter rules; check your exporter config for the exact metric names.
Checklist
1. Is the I/O thread pool saturated?
-
kafka.server:type=KafkaRequestHandlerPool,name=RequestHandlerAvgIdlePercent(attributeOneMinuteRate, 0–1). Sustained values below about 0.3 mean the I/O threads are the bottleneck. -
RequestQueueTimeMsp99 is a large part ofTotalTimeMsfor Produce. -
kafka.network:type=RequestChannel,name=RequestQueueSizestays nearqueued.max.requests(default 500).
Fix: raise num.io.threads (default 8; a common starting point is the number of disks or cores, whichever is lower). It is a dynamic broker config, so no restart is needed:
bin/kafka-configs.sh --bootstrap-server broker1:9092 \
--entity-type brokers --entity-name 1 \
--alter --add-config num.io.threads=16
If idle is low but CPU isn't high, threads are blocked on disk. More threads won't help; go to step 3.
2. Is the network thread pool saturated?
-
kafka.network:type=SocketServer,name=NetworkProcessorAvgIdlePercent(attributeValue). Keep it above about 0.3–0.4. -
ResponseQueueTimeMsrises along with it.
Fix: raise num.network.threads (default 3). TLS listeners cost noticeably more network-thread CPU than plaintext. Also look for clients sending many tiny requests (linger.ms=0, batch.size too small); they burn network threads per byte moved. Request rate is in kafka.network:type=RequestMetrics,name=RequestsPerSec,request=Produce.
3. Is the leader's local work slow?
-
LocalTimeMsfor Produce is high on one broker. - OS disk metrics (
iostat -x 5) show highawaitor%utilon log directories. -
kafka.log:type=LogFlushStats,name=LogFlushRateAndTimeMsis busy. If someone setflush.messagesorflush.mson a topic, Kafka is fsyncing on the request path. - The topic's
compression.typediffers from what producers send. The broker then decompresses and recompresses every batch. Leave it atproducerunless you have a reason not to.
bin/kafka-configs.sh --bootstrap-server broker1:9092 \
--entity-type topics --entity-name orders --describe --all | grep -E 'compression.type|flush'
For FetchConsumer, a high LocalTimeMs usually means lagging consumers are reading cold segments from disk instead of page cache, or (on Kafka 3.x with old clients) message down-conversion. Check kafka.network:type=RequestMetrics,name=MessageConversionsTimeMs,request=Fetch and kafka.server:type=BrokerTopicMetrics,name=FetchMessageConversionsPerSec.
Caution
Don't fix slow disks by setting
unclean.leader.election.enable=trueor droppingmin.insync.replicasto make produces "succeed faster". Both trade latency for silent data loss during the next broker failure.
4. Is the produce waiting on followers?
With acks=all, a Produce request is parked in purgatory until every in-sync replica has fetched the data. RemoteTimeMs is that wait.
-
RemoteTimeMsfor Produce is the largest phase. -
kafka.server:type=DelayedOperationPurgatory,name=PurgatorySize,delayedOperation=Produceis growing. -
kafka.server:type=ReplicaFetcherManager,name=MaxLag,clientId=Replicais high on one or more followers. -
FetchFollowertimings on the leader show its ownLocalTimeMshigh (the leader reads slowly for followers).
# Partitions where the ISR is shrinking, a sign of slow followers
bin/kafka-topics.sh --bootstrap-server broker1:9092 --describe --under-replicated-partitions
Fix: find the slow follower. It's often one broker with a bad disk, a noisy neighbour or a cross-zone link. Then:
- Raise
num.replica.fetchers(default 1) on followers so they fetch from more leaders in parallel. - Check whether a partition reassignment throttle (
leader.replication.throttled.rate,follower.replication.throttled.rate) was left in place after a move. - If the slow broker is the leader, move leadership off it while you investigate. Reassign so it is no longer first in each replica list, then run
bin/kafka-leader-election.sh --bootstrap-server broker1:9092 --election-type preferred --all-topic-partitions.
5. Is fetch latency actually a problem?
-
FetchConsumerTotalTimeMssits close to the consumer'sfetch.max.wait.ms(default 500 ms).
That is normal. The broker holds the fetch in purgatory until fetch.min.bytes arrives or the wait expires, and the wait shows up in RemoteTimeMs. Don't alert on fetch total time for low-volume topics; alert on consumer lag instead.
6. Is a quota throttling the client?
-
ThrottleTimeMsis non-zero for the request type. - Client metric
produce-throttle-time-avgorfetch-throttle-time-avgis non-zero.
bin/kafka-configs.sh --bootstrap-server broker1:9092 --describe --entity-type clients
bin/kafka-configs.sh --bootstrap-server broker1:9092 --describe --entity-type users
Fix: raise the quota for that principal or client ID, or accept that the throttle is doing its job.
7. Is the client or network slow to receive?
-
ResponseSendTimeMsis high while everything else is low.
The broker is waiting for socket buffers to drain. Look at client-side CPU and GC pauses, packet loss between zones, and socket.send.buffer.bytes on high-latency links.
Quick mapping
| Biggest phase | Look at | First change |
|---|---|---|
| Request queue | RequestHandlerAvgIdlePercent | num.io.threads, then disks |
| Local (produce) | Disk await, flush settings, compression | Remove per-topic flush, keep compression.type=producer |
| Local (fetch) | Cold reads, down-conversion | Upgrade old clients, add page cache/RAM |
| Remote (produce) | Purgatory, follower MaxLag | Fix the slow follower, num.replica.fetchers |
| Response queue | NetworkProcessorAvgIdlePercent | num.network.threads, bigger client batches |
| Response send | Client and network | Client GC, network path |
| Throttle | Quotas | Adjust quota |
Prevent it next time
- Dashboard the p99 of every phase for Produce and FetchFollower per broker, next to both idle-percent gauges. A single TotalTimeMs panel hides the cause.
- Alert on
RequestHandlerAvgIdlePercentbelow 0.3 for 10 minutes, and onUnderReplicatedPartitionsabove zero. - Record
num.io.threads,num.network.threadsandnum.replica.fetchersin your broker config in Git. Dynamic changes made during an incident are easy to lose on the next rebuild. - Before adding a large producer, load-test it against one broker and watch the phase breakdown, not just throughput.
Get the weekly HubDatAI email
One email a week with everything new: posts, learning sessions and videos. Free, no spam, unsubscribe in one click. What you get