liveBook · Manning

Network thread

As explained in Apache Kafka in Action

A network thread is a broker thread that handles network communication and contributes to the broker's request-processing capacity.

A network thread is a Kafka broker thread that handles network communication. It receives producer and consumer requests, places them on the request queue, and sends completed responses from the response queue. section 8.2.1 section 9.2

For a produce request, the network thread receives and authorizes the request before queueing it for I/O threads. Those threads write messages to the partition’s current log segment, while a network thread later returns the response after the required wait. section 8.2.1 section 8.5

For a fetch request, the network thread performs the same queueing role. I/O threads read batches from the filesystem or page cache, and a network thread sends the response after fetch conditions are satisfied. section 9.2

Tune network threads according to the broker’s workload:

  • Start with the default of three network threads, but consider six when TLS secures data traffic. section 6.3.1
  • Treat network threads as one part of request capacity; overloaded I/O threads can still make requests wait in the queue. section 8.2.1
  • Use workload measurements before increasing the setting, particularly in production environments handling large data volumes. section 6.3.1

Produce and fetch flows

A producer sends a message to the broker. A network thread queues it, an I/O thread writes it to the page cache, and a network thread eventually returns the acknowledgment. A consumer fetch follows the same entry and exit path, but I/O threads read batches instead of writing them.

Figure 8.3 When a broker receives a produce request (1), it’s put on the request queue (2) and later handled by the I/O threads (3) and written to the page cache (4). The operating system flushes it to disk later. Then, the message stays in purgatory (5) until all in-sync followers acknowledge the message (6). When the wait (7) is over, the response is put on the response queue (8) and sent back to the producer by one of the network threads (9).
A screenshot of a computer screen

AI-generated content may be incorrect.

Trace the complete produce-request path from network reception through request queuing, page-cache writing, replication waiting, and response delivery. section 8.2.1

Figure 9.2 The broker undergoes a similar process when receiving a fetch request as that of when receiving a produce request. However, instead of writing data to the disk, we need to read from it. Additionally, we don’t need to wait for other brokers, but rather for more messages depending on the fetch.max.wait.ms and fetch.min.bytes settings.
A group of colorful buttons

AI-generated content may be incorrect.

Compare the fetch path with produce handling and see how fetch.min.bytes and fetch.max.wait.ms affect response timing. section 9.2

How Apache Kafka in Action covers it

How deep it goes
Explains request queues, I/O-thread handoff, page-cache interaction, response queues, and workload-based tuning.
Examples
Uses produce and fetch request flows plus TLS-related num.network.threads tuning.
What it assumes
Assumes Kafka brokers, producers, consumers, request queues, and I/O threads; distinguishes network work from filesystem work.
What you can do after
Diagnose request-processing bottlenecks and configure network-thread capacity for TLS and high-volume workloads.
How it connects
Connects network threads with Kafka brokers, producers, consumers, I/O threads, request queues, response queues, and replication.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Apache Kafka in Action. The section links point to the parts of the book it draws on.