Course contentsShow
← Node.js
Lesson 522 of 1,9806. Networking and HTTP FundamentalsFree lesson

TCP Segmentation Offloading

Analyze how hardware-level segmentation impacts the data chunks received by your Node.js application.

In this lesson, you will learn how TCP Segmentation Offloading (TSO) changes the way your Node.js application receives data chunks from the network card.

What is TSO?

Normally, when you send a large amount of data, the Operating System must chop it into small TCP segments that fit into the Maximum Transmission Unit (MTU) of the network cable. This is CPU-intensive. With TSO, the OS hands a giant, unsegmented block of data (up to 64KB) directly to the Network Interface Card (NIC), and the hardware handles the fragmentation into packets.

Impact on Your Node.js Application

From the perspective of your Node.js net or http stream, TSO creates an interesting "illusion." Because the NIC is doing the work of assembly and reassembly, your application doesn't see the individual tiny packets that traveled across the wire.

Instead, Node.js receives "blobs" of data that reflect the efficiency of the buffer management between the kernel and the hardware. Because the hardware performs the segmentation, the data events emitted by your socket may contain larger, consolidated chunks than if TSO were disabled.

Consider this snippet:

socket.on('data', (chunk) => {
  console.log(`Received ${chunk.length} bytes`);
});

If you send a 32KB file, in a non-TSO environment, you might receive several smaller data events as individual TCP segments arrive and get reassembled by the OS. With TSO enabled, you are much more likely to receive one or two large, efficient Buffer chunks.

Why This Matters for Streams

Since Node.js relies on the underlying OS buffer to fill the Readable stream, TSO allows your application to process data in larger, more efficient strides. This reduces the number of times the Node.js event loop has to wake up to handle a new data event. By letting the hardware handle the "grunt work" of segmentation, the system achieves higher throughput and lower CPU usage, allowing your stream processors to consume data in fewer, larger bites.

Key Takeaway: TCP Segmentation Offloading shifts the burden of packet fragmentation to your network hardware, which often results in your Node.js application receiving fewer, larger data chunks, thereby improving throughput and reducing event loop overhead.