Latency
Latency is the time one operation takes, from the moment something asks for a result until the result arrives. It applies at every scale, from a processor reading memory to a request crossing the world. Part of it is the time the work itself takes, and part is the time spent travelling or waiting before the work starts. Distance sets a floor that no software can lower, because no signal travels faster than light.
Latency differs from throughput, which is how many operations finish per second. A system can move a great deal of data per second and still make each request wait, and lowering one often costs some of the other. A road is the usual picture: more lanes let more cars pass per hour, but each car still takes as long to arrive. Batching is the common trade, since grouping requests raises throughput while each request waits for its batch to fill.
Latency decides how fast a system feels to the people and programs that wait on it. A workload that makes many calls in sequence pays the latency of each one, so small delays add up quickly. Running the calls in parallel, or merging them into fewer calls, cuts the total because the waits overlap or disappear. An agent that runs tools in a loop cannot do this easily, since each step depends on the result of the last tool call.
Orders of magnitude
Orders of magnitude of latency are the rough scales that common operations fall into, from the processor to the far side of the world. Exact values vary with hardware and distance, but the scale stays the same. The gaps come from distance and from the number of devices a request has to cross. A cache sits on the processor itself, while a network round trip passes through many devices on the way.
The slowest common operations are millions of times slower than the fastest. A program that moves an operation from one scale to a faster one often gains more than any tuning of its code. This is also why code that looks efficient can still be slow, if it reads from disk or the network inside a loop. Counting the slow operations a request makes often explains its speed better than profiling its code.
Most performance work is about moving operations to a faster row. Keeping memory on the same NUMA node as the processor helps inside a machine, and keeping a service in the same region as its users helps across the network. Caching follows the same idea, since a result kept close is read from a fast row instead of fetched from a slow one. Services that talk to each other often gain the most from being placed close together.
| Operation | Typical latency |
|---|---|
| Read from the first-level cache of the processor | About a nanosecond |
| Read from main memory | Around a hundred nanoseconds |
| Read from a local NVMe disk | Tens of microseconds |
| Round trip within a datacenter | Hundreds of microseconds |
| Round trip across a continent | Tens of milliseconds |
Averages and tails
Averages and tails are the two ends of a latency distribution, which is how latency is reported instead of as a single number. The median, or p50, is what a typical request sees. A distribution is needed because latency varies from one request to the next, even for identical work. The mean is rarely used, because a few very slow requests pull it far from what most requests see.
The 99th percentile, or p99, is the latency that 99 in a hundred requests meet or beat. It is often many times higher than the median, because of queueing or a busy neighbor on the same host. Garbage collection pauses and retries after a lost packet cause it too. Each of these events is rare for any one request, so it hides in the average and shows up only in the tail.
Tail latency matters more than it seems. A page that makes dozens of backend calls waits for the slowest of them, so its speed depends on the tail rather than the median. Even if each call is slow only rarely, a page that waits on many of them hits a slow one on a large share of its loads. Some systems send a duplicate request after a short wait and use whichever answer arrives first.
Start-up latency
Start-up latency is the delay before a workload can begin any work. For short-lived workloads it can take longer than the work itself, and a user who waits on it notices it directly. It is paid once per environment, so its weight depends on how much work follows it. A service that runs for months barely notices it, while a brief task can spend most of its life starting.
Booting a virtual machine and pulling an image are the usual sources of the delay. Starting a language runtime adds more on top. Pulling an image is often the largest part, because its layers have to cross the network before anything can run. Booting is faster in a microVM, which leaves out most of the devices a full virtual machine emulates.
Platforms reduce start-up latency in two common ways. They restore a snapshot instead of booting, or they keep a pool of environments ready before anyone asks for one. A snapshot holds the memory of an environment that has already booted and loaded its runtime, so restoring it skips both steps. A pool trades the other way, paying for idle environments so that none has to start on demand.