Large-scale cluster management at Google with Borg
2015 · EuroSys · ~12 min read
Read the original paperBorg runs Google’s services and batch jobs on shared cells of about ten thousand machines, using priorities, quota and preemption to decide who gets what. Read it to see where Kubernetes’ model came from and how the savings from sharing were measured.
Every service at Google, from web search to Gmail, and every batch job, from MapReduce to index builds, needs machines. The simple answer is to give each team its own. That wastes a great deal: a serving team must own enough machines for its daily peak, which leaves most of them idle at night, while a batch team wants a burst of a thousand machines for three hours and nothing afterwards. Sharing one pool of machines between them recovers the waste, but raises hard questions. Who gets a machine when the pool is full? What happens to a batch task when a serving task needs its machine? How does a client find a server that could be anywhere? And how does the whole thing keep running when machines, racks and the control system itself fail?
Google had answered these questions in Borg by the mid-2000s and ran almost everything on it for a decade before publishing this paper in 2015, a year after releasing Kubernetes. After this page you should be able to follow one job from submission to running tasks, explain why a production task can evict a batch task but not another production task, explain how Borg measured the savings from sharing, and map Borg’s concepts onto Kubernetes.
We will follow one job. A team submits web, a production service of three tasks, each asking for 2 CPU cores and 4 GiB of memory, to a cell whose machines are already busy with a large batch indexing job.
The contract a user signs
Borg manages a cell, a set of machines in one cluster, with about 10,000 machines in a median cell. A user submits a job: a name, a binary, a number of identical tasks, a resource request per task, constraints such as a processor type, and a priority. Jobs are written in a configuration language called BCL. As a sketch (this is not real BCL syntax), our job says:
job web {
cell = "cc"
binary = "/team/web/server"
priority = production
replicas = 3
per task = { cpu: 2.0 cores, ram: 4 GiB }
}Priorities fall into bands. From highest to lowest the paper names monitoring, production, batch and best effort. A higher-priority task can take a machine from a lower one by evicting it. There is one important exception: tasks in the production band are not allowed to evict each other. Without that rule a production task could evict another, which would then evict a third, and so on through the cell. The paper calls this a preemption cascade, and forbidding it within the band keeps production stable.
Priority decides who wins when machines are full. Quota decides who is allowed to submit at all. A team buys quota as a vector of resources (CPU, memory, disk and so on) at a given priority for a period such as a month. Borg checks quota when a job is submitted and rejects jobs that exceed it, so admission control happens before scheduling. Quota at the highest priorities is sold carefully, which is what makes it safe to schedule production as if batch did not exist. Every user effectively has unlimited quota at priority zero, but jobs there get only what is left over.
Placing one task
When web is accepted, its three tasks go into the pending queue. The scheduler works through the queue from high priority to low, and for each task it does two things. Feasibility checking finds machines that meet the task’s constraints and have enough resources, counting resources that could be freed by evicting lower-priority tasks. Scoring then ranks the feasible machines.
Take web’s first task. Machine M1 has 16 cores, 15 of them used by indexing tasks; it is feasible, because evicting batch tasks would free room. Machine M2 has 4 free cores and already has the web binary in its local package cache; it is feasible without evicting anything. Scoring prefers M2. Among the criteria the paper lists are minimising the number and priority of tasks that must be evicted, preferring machines that already have the task’s packages, spreading a job’s tasks across power and failure domains, and mixing high- and low-priority tasks on each machine so that a load spike can be absorbed by evicting batch work.
Package locality matters more than it might seem. The paper reports a median task startup of about 25 seconds, of which about 80 per cent was package installation. Placing a task where its binary is already cached removes most of that delay.
Change one variable. Suppose every machine is full and has no spare cores at all. For a production task, the scheduler picks a machine and evicts batch tasks to make room, and the evicted tasks go back to the pending queue to be placed again when space frees up. For a batch task in the same situation, nothing happens: it waits in the queue. That asymmetry is the scheduling policy.
The paper also explains how scoring balances two goals that conflict. Worst fit spreads load and leaves headroom on every machine, but fragments free space so that large tasks cannot fit anywhere. Best fit packs tightly, but leaves no slack for spikes and hurts bursty workloads. Borg uses a hybrid that tries to reduce stranded resources, meaning resources left unusable on a machine because some other resource there is used up. To make scoring fast across 10,000 machines, the scheduler caches scores, groups tasks with identical requirements so each group is scored once, and examines machines in random order until it has found enough good candidates rather than scoring every machine.
Why one shared pool beats two
The economic argument for Borg rests on one measurement, and the paper is careful about how it was made. To compare policies, the authors used cell compaction: take a real workload from a production cell, then remove machines until the workload no longer fits, using Borg’s own scheduler running offline. The smallest cell that still fits measures how efficient a policy is. They repeated the process many times with different random seeds to get a distribution.
If production and batch work ran in separate cells instead of one shared cell, would the total machine count go up or down, and roughly by how much?
Show the worked answer
Up. Production tasks request resources for their peaks and use less most of the time; batch work can use what they leave idle. Separate the two and that idle capacity is stranded in the production cell while the batch cell needs its own machines.
The paper found that segregating production from non-production work would need 20 to 30 per cent more machines in the median cell. It also found that rounding resource requests up to fixed sizes, rather than letting users ask for fractions of a core and exact amounts of memory, would need 30 to 50 per cent more resources in the median case.
Production jobs must run; batch jobs run when they can. Submit both and watch placement, eviction and the machines you would need if the two kinds had separate clusters.
Priority is the whole trick. Production work is placed as if the batch work were not there; batch work soaks up the gaps and accepts being thrown out. Separate clusters would each need headroom for their own peaks; one pool shares the headroom.
In this small model, production tasks are placed first and evict batch tasks when needed. The evicted tasks wait and return when space frees up. The final readout compares the shared pool with two separate pools; the direction matches the paper even though the model is tiny.
Lending out what tasks asked for but did not use
Users ask for more than they use, because running out of memory kills a task and nobody wants that page. Borg recovers the difference through resource reclamation. A task’s request is its limit. Borg also keeps a reservation, its estimate of what the task will actually use. The reservation starts equal to the limit, and after an initial period, to allow for startup, it decays slowly toward the measured usage plus a safety margin. Production tasks are scheduled against limits. Batch tasks are scheduled against reservations, so they can use the gap between what production asked for and what it uses.
Follow one web task. It asked for 4 GiB and settles at about 1.5 GiB. Its reservation decays to around 2 GiB, and roughly 2 GiB on that machine becomes available for batch. Now web receives a traffic spike and its memory use climbs to 3.5 GiB. What happens next depends on the type of resource. Memory is non-compressible: it cannot be taken back gradually, so the Borglet evicts lower-priority tasks on that machine, starting with batch, until webfits. CPU is compressible: the Borglet throttles batch tasks’ CPU and latency-sensitive tasks keep running. The batch work pays for the spike, which is what it agreed to.
The paper reports that about 20 per cent of the workload in a median cell ran on reclaimed resources. It also describes an experiment comparing more and less aggressive estimates: more aggressive reclamation freed more capacity but caused more out-of-memory events. That is the trade, and the paper chose a middle setting.
Keeping the control plane small and alive
The Borgmaster runs as five replicas that use Paxos to agree on the cell’s state, with one elected leader handling changes. State is saved as periodic checkpoints plus a change log. A Borglet on every machine starts and stops tasks, restarts them when they fail, and reports state when the master polls it. Polling is spread across replicas, each owning a shard of the machines, so that the leader receives only changes. If a machine does not respond to several polls, it is marked down and its tasks are rescheduled elsewhere.
The important design property is that running tasks do not depend on the master. If the whole Borgmaster is unavailable, Borglets keep their tasks running; nobody can submit or change jobs until it returns. The paper reports Borgmaster availability around 99.99 per cent. Checkpoints were also loaded into a simulator called Fauxmaster, which ran the real scheduler code offline to debug decisions and answer capacity questions such as whether a new job would fit.
Two more services make the shared pool usable. The Borg name service records each task’s hostname and port in Chubby, so clients can find tasks wherever they run. And every task exposes a health endpoint and metrics, and Borg provides user interfaces that explain, for example, why a task is still pending. The paper treats this introspection as essential, since users of a shared system cannot log in to a machine they own to find out what is happening.
Sharing a machine needs isolation between the tasks on it, and section 6 of the paper is candid about how far Borg went. Tasks run in Linux containers built from chroot and cgroups, which separate resources well enough for tasks that all belong to Google employees. Borg does not treat containers as a security boundary against hostile code. The externally facing products that ran customer code, App Engine and Compute Engine, ran their workloads inside virtual machines under KVM, launched as Borg tasks. Performance isolation was the harder daily problem: the paper describes CPU throttling, kernel changes to the scheduler, and classifying tasks as latency-sensitive or batch so that the Borglet can protect the first from the second on a busy machine.
A rack loses power
Walk through a failure with our job. The rack holding one of web’s three tasks loses power. The Borgmaster’s pollers get no reply from those Borglets; after several missed polls the machines are marked down and their tasks go back into the pending queue. Because the scheduler had spread web’s tasks across failure domains, this rack held only one of them. The other two keep serving while the third is rescheduled somewhere else, where it may in turn evict batch work.
Now the rack comes back. Its Borglets restart and report their tasks, including the old copy of web, which is still running. Borg already has a replacement elsewhere, so the master tells the Borglet to kill the old copy. Without that step, a network partition would leave two copies of a task that is supposed to exist once.
Planned disruption is handled with the same care. Kernel upgrades and machine maintenance take machines away on purpose, and Borg limits how quickly it disrupts a job’s tasks and how many of a job’s tasks can be down at once. Kubernetes exposes the same idea as a pod disruption budget.
Batch users see the other side of these rules. A MapReduce worker evicted halfway through a task loses its progress, and the MapReduce master runs the task again somewhere else. Batch frameworks at Google were written to expect this, with re-execution and checkpointing built in. The cheapness of the batch band depends on the batch software being able to lose work and recover. A batch job that cannot restart safely does not belong in a band that promises eviction.
What Kubernetes kept and what it changed
Section 8 of the paper lists lessons, and several of them are explicitly about decisions Kubernetes reversed.
| Borg | Problem the authors saw | Kubernetes |
|---|---|---|
| jobs as the only way to group tasks | users encoded structure in job names and needed many workarounds | labels and selectors on any object |
| one IP per machine; ports allocated as a resource | every task and client had to handle dynamic ports | one IP per pod |
| allocs: reserved resources shared by helper tasks | useful, but bolted on | pods as the basic unit |
| a monolithic Borgmaster, with a large job specification | hard to extend; tuned for expert users | an API server with separate controllers that reconcile desired state |
| limits, reservations, priority, preemption | kept | requests, limits, priority classes, preemption |
The companion article “Borg, Omega, and Kubernetes” in ACM Queue (2016), by several of the same people, discusses these choices at more length. Outside Google, Borg’s model of bin-packing with priorities is the model of Mesos, YARN, Nomad and Kubernetes. Spot and preemptible cloud instances sell the batch band to the public: cheap capacity that can be taken back.
A Borg-style shared pool pays off when the workload mix is varied, especially when latency-sensitive services with daily peaks can share machines with batch work that is willing to be evicted. With a small cluster and one kind of workload, the savings come mostly from right-sizing requests, and the complexity of priorities and preemption may not be worth it.
How to read the original
Read section 2, the user’s view of jobs, priorities, quota and naming, closely; most of the paper relies on it. In section 3, read the scheduling subsection carefully and skim the Borglet. Section 3.4 on scalability is worth a skim for the tricks. Section 4, on availability, can be skimmed.
Section 5, on utilisation, is the heart of the evaluation. Understand the cell compaction method before looking at the figures, then read each figure as a distribution across cells rather than a single number, and note that the results come from Google’s workloads. Section 6 covers isolation, including the split between compressible and non-compressible resources. Section 8, lessons learned, is the part most worth rereading if you work with Kubernetes.
Borg isolates tasks with Linux containers, which is fine when every tenant works for the same company. The next paper, Firecracker, asks what changes when the tenants are strangers who may be hostile.
The original. Read it after this page; the explainer above is a map, not a substitute.
The same authors on the lessons from three generations of cluster managers.
Read the paper, then this: the vocabulary maps almost one to one.