为何不同TCP端口意味着两个HTTP网络请求串行执行?
Great question—let's unpack this logic clearly, since it ties together how HTTP uses TCP under the hood.
First, let's set some baseline definitions to avoid confusion:
- Serial HTTP requests: One request finishes completely (the full response is received, and the underlying TCP connection is often closed) before the next request is even initiated.
- Parallel HTTP requests: Multiple requests are in flight at the same time—each has its own active TCP connection, and these connections exist simultaneously.
Now, let's connect this to TCP ports:
When a client sends an HTTP request, it uses a unique local TCP port (from the ephemeral port range, usually 1024-65535) to communicate with the server's standard port (like 80 for HTTP, 443 for HTTPS). Each TCP connection is uniquely identified by the combination of client IP + client port + server IP + server port.
So why would different client ports point to serial execution? Here's the key:
If the two HTTP requests use different local ports, and their corresponding TCP connections were created sequentially (not overlapping in time), that tells us the first connection was fully closed before the second one was established. This only happens when you wait for the first request to finish before starting the second—aka serial execution.
To contrast, parallel requests would also use different local ports, but those TCP connections would be active at the same time (their lifecycle timestamps overlap). So it's not just "different ports" that matters—it's the fact that the ports were used one after another, with no overlap, which signals serial behavior.
A quick side note: If your requests were using HTTP/1.1 with Keep-Alive enabled, serial requests might reuse the same TCP port (since the connection stays open for multiple requests). But in cases where Keep-Alive is disabled (like HTTP/1.0 default behavior), each serial request will spin up a new TCP connection with a new local port—exactly the scenario your answer is referencing.
内容的提问来源于stack exchange,提问作者sbdchd

