Implementing Zero-Copy I/O using sendfile and splice for Network Services
The naive approach to serving files over a network burns CPU cycles copying the same bytes multiple times. Reading a 100MB file from disk and sending it over a socket with traditional
read()/write()loops forces the kernel to copy that data four times: disk → page cache → user buffer → kernel socket buffer → NIC. Each copy consumes memory bandwidth and CPU cycles. On a 10Gbps network pushing 1.25GB/s, this copying overhead can eat 40% of your CPU just shuffling bytes around.When Netflix analyzed their CDN edge servers, they found 15% CPU usage from video streaming workers. Most of that was
memcpy()between kernel and userspace. Switching tosendfile()dropped it to 2% - the kernel transferred data directly from page cache to socket buffers, letting DMA handle the NIC transfer while the CPU did useful work.


