Experimental Analysis of TCP Connection Memory Consumption in Different Socket States
This article presents a seven‑day experiment measuring how much memory a TCP connection occupies in the kernel under various states such as ESTABLISH, data transfer, and TIME_WAIT, and summarizes the kernel's memory‑optimisation techniques for sockets.
The article investigates the actual memory footprint of a TCP connection in the Linux kernel, considering real‑world scenarios where connections send and receive data and transition through states like ESTABLISH, TIME_WAIT, and others.
Experiment 1: ESTABLISH (idle) connection – Images illustrate the memory usage of a newly established socket without data transfer.
Experiment 2: Client → Server data transmission – Measurements show memory consumption when the client sends data to the server.
Experiment 3: Server → Client data transmission – Similar measurements for data flowing from server to client.
Experiment 4: Non‑ESTABLISH states – Includes observations for sockets in states such as TIME_WAIT, highlighting additional memory reclamation.
The final summary consolidates the findings, noting that the kernel employs several strategies to reduce socket memory usage:
The kernel promptly recycles send and receive buffers, with newer kernel versions improving this behavior.
The minimum size of these buffers is not strictly tied to the rmem kernel parameter and can be smaller in practice.
In other states, for example TIME_WAIT, the kernel also frees unnecessary objects like socket_alloc .
Overall, the experiments demonstrate that kernel-level optimisations significantly affect the memory overhead of TCP connections.
Architecture Digest
Focusing on Java backend development, covering application architecture from top-tier internet companies (high availability, high performance, high stability), big data, machine learning, Java architecture, and other popular fields.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.