Saltar al contenido principal

The Round Trip Is the Enemy: How One Connection Does a Million Ops

· 10 min de lectura
Clustron Team
Ingeniería de Sistemas Distribuidos

Here is a number that surprises people the first time they measure it: a client talking to a cache that can serve a key in two microseconds will often get only a few thousand operations per second out of a single connection. The server is barely awake. The network has bandwidth to spare. And yet the throughput is dismal, and no amount of server tuning moves it. The bottleneck is somewhere neither of those numbers describes.

The culprit is the round trip. If a client sends a request and then waits for the response before sending the next one, the connection spends almost all of its time in flight — the request crossing to the server, the response crossing back — and almost none of it doing work at either end. At a round-trip time of 200 microseconds, that waiting alone caps the connection at 5,000 operations per second, no matter how fast the store is, because the client issues exactly one request per round trip and the round trip is the clock. The server processes for 2 microseconds and idles for 198. The wire carries one small request, then falls silent for the return leg. Everyone is waiting for everyone else.

This is the single most common reason a fast store feels slow, and the fix is not a faster network or a bigger server. It is to stop waiting. Pipelining lets one connection keep many requests in flight at once, so the round trip stops being the clock and the server's actual processing rate takes over. This post is about why that works, why it is safe to do without tagging every request with an ID, and the one tradeoff it quietly makes.

Why waiting is the whole cost​

Walk through what a synchronous request-reply actually spends its time on. The client serializes a GET, writes it to the socket, and blocks. The request travels the wire — that is half the round trip, and both the client and the server are idle for it. The server deserializes, does its two microseconds of real work, and writes the reply. The reply travels back — the other half of the round trip, everyone idle again. Only now does the client unblock, read the response, and get to send request number two.

The arithmetic is unforgiving: the connection completes one operation per round trip, so its ceiling is 1 / RTT operations per second regardless of server speed. The server's capacity — millions of ops per second — never enters the equation, because the client never lets more than one request exist at a time. You have bought a sports car and are driving it one length forward, stopping, and waiting for a letter to confirm you may drive the next length.

The waste is not the work; it is the serialization of the waiting. Nothing about the problem requires request two to wait for response one. They are independent operations. The only reason they are serialized is that the client chose to block, and that choice is the entire bottleneck.

Pipelining: fill the wire, correlate by order​

Pipelining is the decision to send the next request without waiting for the previous response. The client writes request one, and instead of blocking, immediately writes requests two, three, and a hundred more, as fast as the application produces them. Meanwhile a reader pulls responses off the socket as they arrive. At steady state the connection is full: requests streaming out, responses streaming back, both ends busy, the wire carrying traffic in both directions continuously. The round trip is still 200 microseconds, but it is no longer the clock — it is just latency that a hundred in-flight requests are hidden behind. Throughput is now bounded by whichever is slower, the server's processing rate or the link's bandwidth, and for small operations that means the server, which is exactly where you wanted the bottleneck to be.

The question this raises is: when a response arrives, how does the client know which request it answers, if a hundred are outstanding? The elegant answer is that it does not need to ask. TCP is an ordered byte stream, and the server processes the requests on a connection in the order it receives them and writes each reply before moving to the next. So the responses come back in exactly the order the requests went out. The client keeps a FIFO queue of the pending requests, and when a response arrives it belongs, with certainty, to the request at the head of that queue. No request IDs, no correlation tokens, no matching logic — position is the correlation. The first response is request one's, the second is request two's, and the ordering guarantee of the underlying stream makes that true for free.

pending (FIFO):  [ GET a ][ SET b ][ INCR c ][ GET d ] ...
↑
response arrives → belongs to the head, always.
dequeue, complete its awaiter, move on.

This is how a Zaris client — whether speaking the native protocol or RESP — turns one socket into a firehose. The caller's await on an individual operation suspends only that caller; the connection itself never blocks, because the request is written and its completion is parked in the pending queue while the writer moves straight on to the next.

Synchronous: 1 op per round trip — wire mostly idleclientserverreq 1 →← reply 1 (then, and only then, req 2)both ends idle for the whole round tripPipelined: requests back-to-back, replies stream back in orderclientserverreq 1, 2, 3, 4 … (no wait)← replies 1, 2, 3, 4 … in the same orderpending FIFO: [req1][req2][req3][req4] → head matches next replywire stays full · throughput bounded by the SERVER, not the round tripposition is the correlation — no request IDs needed

The one cost: head-of-line​

Positional correlation is what makes pipelining cheap, and it is also the source of its single downside. Because responses must be delivered to their callers in order, a slow operation at the head of the queue holds up every response behind it — even responses that have already physically arrived cannot be handed to their callers until the head is resolved, since handing them out early would break the positional match. One GET on a huge value, or a command that blocks server-side, stalls the fast operations queued behind it on that connection.

For the overwhelming majority of workloads — streams of small, quick operations — this never bites, because nothing sits at the head long enough to matter. Where it can bite is a mix of one occasionally-slow command with a flood of fast ones on the same connection. The remedy is not to abandon pipelining but to not share a connection between traffic classes with wildly different latencies: keep the big, slow, or blocking operations off the connection carrying your fast hot-path traffic. This is a far smaller tax than the round-trip ceiling it replaces.

Why you need fewer connections than you think​

The practical consequence runs against a common instinct. Faced with a throughput target, people reach for a large connection pool — hundreds or thousands of sockets — reasoning that more connections means more parallelism. With pipelining, a single connection can already saturate a server core with in-flight work, so a handful of connections typically reaches the server's ceiling, and piling on more adds context-switching and memory overhead without adding throughput. The parallelism you wanted was never in the number of connections; it was in the number of requests in flight, and one pipelined connection supplies plenty of that. Pipelining does not change the semantics of any operation — each command is still independent, still atomic on its own, still isolated from the next — it changes only when the client chooses to wait, and that single change is the difference between a few thousand ops a second and a few million.

Wrap-up​

A fast store with a slow client is almost always a client that waits. The round trip is a fixed latency, and a connection that completes one operation per round trip has turned that latency into its throughput ceiling, leaving the server idle and the wire empty for the entire trip. Pipelining hides the latency instead of paying it per operation: keep many requests in flight, let the ordered stream bring the responses back in the order they were asked, and match each to the head of a pending queue so correlation costs nothing. The price is head-of-line ordering, which a little connection hygiene keeps harmless, and the reward is a connection whose throughput is governed by how fast the server can actually work — which is the only limit you ever wanted to be hitting.