Home / Data Platform / Streaming & CDC

Data PlatformChecklistAdvanced

Kafka broker request latency checklist: split TotalTimeMs into queue, local, remote and send time to find the bottleneck

When Kafka produce or fetch latency rises, break each request into its phases with broker JMX metrics, find the saturated thread pool, disk or follower, and apply the matching fix.

Deepak Bhardwaj7 min read

Applies toApache Kafka 3.x and 4.x brokers (KRaft or ZooKeeper), Confluent Platform; metric names are the Apache Kafka JMX names

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 (attribute OneMinuteRate, 0–1). Sustained values below about 0.3 mean the I/O threads are the bottleneck.
  • RequestQueueTimeMs p99 is a large part of TotalTimeMs for Produce.
  • kafka.network:type=RequestChannel,name=RequestQueueSize stays near queued.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 (attribute Value). Keep it above about 0.3–0.4.
  • ResponseQueueTimeMs rises 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?

  • LocalTimeMs for Produce is high on one broker.
  • OS disk metrics (iostat -x 5) show high await or %util on log directories.
  • kafka.log:type=LogFlushStats,name=LogFlushRateAndTimeMs is busy. If someone set flush.messages or flush.ms on a topic, Kafka is fsyncing on the request path.
  • The topic's compression.type differs from what producers send. The broker then decompresses and recompresses every batch. Leave it at producer unless 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=true or dropping min.insync.replicas to 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.

  • RemoteTimeMs for Produce is the largest phase.
  • kafka.server:type=DelayedOperationPurgatory,name=PurgatorySize,delayedOperation=Produce is growing.
  • kafka.server:type=ReplicaFetcherManager,name=MaxLag,clientId=Replica is high on one or more followers.
  • FetchFollower timings on the leader show its own LocalTimeMs high (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?

  • FetchConsumer TotalTimeMs sits close to the consumer's fetch.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?

  • ThrottleTimeMs is non-zero for the request type.
  • Client metric produce-throttle-time-avg or fetch-throttle-time-avg is 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?

  • ResponseSendTimeMs is 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 RequestHandlerAvgIdlePercent below 0.3 for 10 minutes, and on UnderReplicatedPartitions above zero.
  • Record num.io.threads, num.network.threads and num.replica.fetchers in 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.