TExcelTAD
Home › Online Algorithms & Competitive Analysis › The k-Server Problem and Its Conjecture

The k-Server Problem and Its Conjecture

Paging asks which page to evict; all evictions cost the same. Give the pages locations in space, make the cost of serving a request depend on how far something must move, and paging becomes the kk-server problem of Manasse, McGeoch and Sleator (1988; journal version 1990). It is the most studied problem in competitive analysis, partly because its central question has resisted every attack: is there a deterministic kk-competitive algorithm on every metric space? This lesson defines the problem, proves the lower bound kk on every metric, shows that the obvious greedy rule fails, and states carefully what is known about the conjecture.

The problem

There is a metric space (M,d)(M, d) and kk servers located at points of MM. Each request is a point r∈Mr \in M; to serve it, some server must move to rr (if a server is already there, the request costs nothing). The cost is the total distance moved by all servers. An online algorithm decides which server to send, without knowing future requests.

  • Paging is the kk-server problem on the uniform metric, all distances 1: points are pages, a server at a point means the page is cached, and moving a server is evicting one page and loading another.
  • Weighted paging (pages with different load costs) is the kk-server problem on a star, a weighted tree with the pages as leaves.
  • Motivation from the original paper: disk heads or repair vehicles that must travel to requests, which is where the name comes from.

A lazy algorithm moves only one server per request, the one that serves it. Any algorithm can be made lazy without increasing its cost (by the triangle inequality, a server's detours can be postponed until it is needed), so OPT can be assumed lazy. OPT itself is computable in polynomial time by a minimum-cost flow (Chrobak, Karloff, Payne and Vishwanathan, 1991); for small instances dynamic programming over configurations is enough.

Greedy is not competitive

The natural rule, send the closest server, fails badly. On a line, put servers at 0 and 100 and request 1, 0, 1, 0, ... Greedy shuttles the server near 0 back and forth, paying 1 per request forever, while OPT moves the far server to 1 once (cost 99) and then pays nothing.

python · try it yourself
from itertools import combinations

def opt_cost(start, reqs):
    """Offline optimum by dynamic programming over lazy configurations (sorted tuples)."""
    dp = {tuple(sorted(start)): 0}
    for r in reqs:
        nxt = {}
        for conf, c in dp.items():
            if r in conf:
                options = [(conf, 0)]
            else:
                options = [(tuple(sorted(conf[:i] + (r,) + conf[i + 1:])), abs(conf[i] - r)) for i in range(len(conf))]
            for new, extra in options:
                if c + extra < nxt.get(new, float("inf")):
                    nxt[new] = c + extra
        dp = nxt
    return min(dp.values())

def greedy_cost(start, reqs):
    servers, cost = list(start), 0
    for r in reqs:
        i = min(range(len(servers)), key=lambda j: (abs(servers[j] - r), j))
        cost += abs(servers[i] - r)
        servers[i] = r
    return cost

start = (0, 100)
for n in [10, 100, 1000]:
    reqs = [1, 0] * (n // 2)
    print(f"{n:5} requests: greedy {greedy_cost(start, reqs):5}, OPT {opt_cost(start, reqs):3}")
   10 requests: greedy    10, OPT  10
  100 requests: greedy   100, OPT  99
 1000 requests: greedy  1000, OPT  99

The greedy cost grows linearly while OPT stays at 99, so greedy is not cc-competitive for any cc. Greedy ignores the future entirely; a competitive algorithm must sometimes move a far server even though a near one could serve the request more cheaply now. Double Coverage does exactly that, in a controlled way.

The lower bound kk, on every metric

Theorem (Manasse, McGeoch and Sleator, 1990). On every metric space with at least k+1k + 1 points, no deterministic online kk-server algorithm has competitive ratio less than kk.

Proof (the averaging argument)

Fix k+1k + 1 points and a deterministic algorithm ALG whose servers occupy kk of them. The adversary always requests the one point not covered by ALG. Then ALG moves some server from a point xx to the request rtr_t, and the next request is rt+1=xr_{t+1} = x, the point ALG just left. So ALG pays exactly d(rt+1,rt)d(r_{t+1}, r_t) at step tt (if ALG moves more than one server it pays even more), and

ALG(σ)≥∑td(rt,rt+1).\mathrm{ALG}(\sigma) \ge \sum_{t} d(r_t, r_{t+1}) .

Now define kk offline algorithms B1,…,BkB_1, \ldots, B_k. Each occupies kk of the k+1k + 1 points, and they are chosen so that their uncovered points are kk different points, all different from r1r_1. Each BjB_j serves a request rtr_t as follows: if BjB_j covers rtr_t, do nothing; otherwise move the server at rt−1r_{t-1} to rtr_t.

Invariant: just before request rtr_t, all the BjB_j cover rt−1r_{t-1} and their uncovered points are exactly the kk points other than rt−1r_{t-1}. Since rt≠rt−1r_t \ne r_{t-1}, exactly one BjB_j misses rtr_t; it moves its server from rt−1r_{t-1} to rtr_t, so its uncovered point becomes rt−1r_{t-1}, and the invariant holds again with rtr_t in place of rt−1r_{t-1}.

So at each step exactly one of the kk algorithms pays d(rt−1,rt)d(r_{t-1}, r_t) and the others pay nothing. Summing, ∑jBj(σ)=∑td(rt−1,rt)\sum_j B_j(\sigma) = \sum_t d(r_{t-1}, r_t), plus a bounded start-up term for moving the BjB_j into their initial configurations. The cheapest BjB_j pays at most the average, so

OPT(σ)≤1k∑jBj(σ)≤1k ALG(σ)+const,\mathrm{OPT}(\sigma) \le \frac{1}{k} \sum_j B_j(\sigma) \le \frac{1}{k}\,\mathrm{ALG}(\sigma) + \text{const},

and the sums grow without bound as the sequence gets longer.

The program runs this adversary on random metrics of k+1k + 1 points against two deterministic algorithms (greedy, and "move the server that has moved least so far") and checks both the inequality and the averaging identity with an exact OPT.

python · try it yourself
import random
from itertools import permutations

def opt_general(d, start, reqs):
    dp = {frozenset(start): 0}
    for r in reqs:
        nxt = {}
        for conf, c in dp.items():
            options = [(conf, 0)] if r in conf else [(conf - {x} | {r}, d[x][r]) for x in conf]
            for new, extra in options:
                nxt[new] = min(nxt.get(new, float("inf")), c + extra)
        dp = nxt
    return min(dp.values())

def adversary(d, k, rule, steps):
    servers, moved, cost, reqs = list(range(k)), [0] * k, 0, []
    for _ in range(steps):
        r = next(p for p in range(k + 1) if p not in servers)
        reqs.append(r)
        i = rule(d, servers, moved, r)
        cost += d[servers[i]][r]
        moved[i] += d[servers[i]][r]
        servers[i] = r
    return cost, reqs

greedy = lambda d, s, moved, r: min(range(len(s)), key=lambda j: (d[s[j]][r], j))
least_moved = lambda d, s, moved, r: min(range(len(s)), key=lambda j: (moved[j], j))

rng = random.Random(9)
for k in [2, 3, 4]:
    pts = [(rng.random(), rng.random()) for _ in range(k + 1)]
    d = [[round(((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2) ** 0.5, 4) for b in pts] for a in pts]
    for name, rule in [("greedy", greedy), ("least-moved", least_moved)]:
        alg, reqs = adversary(d, k, rule, 600)
        tour = sum(d[a][b] for a, b in zip(reqs, reqs[1:]))
        opt = opt_general(d, range(k), reqs)
        print(f"k = {k}, {name:11}: ALG {alg:8.3f}, sum d(r_t, r_t+1) {tour:8.3f}, OPT {opt:7.3f}, ALG/OPT {alg / opt:.3f}")
k = 2, greedy     : ALG  232.200, sum d(r_t, r_t+1)  231.813, OPT   0.475, ALG/OPT 489.254
k = 2, least-moved: ALG  290.400, sum d(r_t, r_t+1)  290.013, OPT 145.200, ALG/OPT 2.000
k = 3, greedy     : ALG  133.320, sum d(r_t, r_t+1)  133.098, OPT   0.419, ALG/OPT 318.034
k = 3, least-moved: ALG  342.799, sum d(r_t, r_t+1)  342.380, OPT  66.882, ALG/OPT 5.125
k = 4, greedy     : ALG  103.057, sum d(r_t, r_t+1)  102.885, OPT   0.417, ALG/OPT 246.902
k = 4, least-moved: ALG  323.005, sum d(r_t, r_t+1)  322.373, OPT  30.498, ALG/OPT 10.591

Both algorithms pay at least kk times OPT (up to the start-up term), whatever their rule: the adversary's sequence is built from the algorithm's own moves, and ALG's cost equals the length of the request tour ∑td(rt,rt+1)\sum_t d(r_t, r_{t+1}) up to its first step. Greedy is far worse than kk here; the theorem only says that no algorithm escapes below kk.

In C++

Offline OPT by dynamic programming for k=2k = 2 on a line, the tool used to evaluate online algorithms in experiments. A lazy configuration is a pair of server positions; every request moves one of the two servers. For nn requests the table has one entry per possible position of the other server (a previous request or a start position), so the program runs in O(n2)O(n^2) time.

cpp · try it yourself
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <random>
#include <vector>

int main() {
    std::mt19937 rng(10);
    std::vector<long long> reqs;
    for (int t = 0; t < 2000; ++t) {
        bool left = rng() % 2;
        reqs.push_back(left ? rng() % 20 : 980 + rng() % 20);   // two clusters far apart
    }
    // dp: position of the server NOT at the last request -> min cost; last request = where the other server is
    std::map<long long, long long> dp = {{1000, 0}};           // servers start at 0 and 1000, "last" = 0
    long long last = 0;
    for (long long r : reqs) {
        std::map<long long, long long> nxt;
        for (auto [other, c] : dp) {
            auto relax = [&](long long o, long long v) {
                auto it = nxt.find(o);
                if (it == nxt.end() || v < it->second) nxt[o] = v;
            };
            relax(other, c + std::llabs(last - r));                  // the server at `last` moves to r
            relax(last, c + std::llabs(other - r));                  // the other server moves to r
        }
        dp.swap(nxt);
        last = r;
    }
    long long opt = dp.begin()->second;
    for (auto [o, c] : dp) opt = std::min(opt, c);
    long long greedy = 0, a = 0, b = 1000;
    for (long long r : reqs) {
        if (std::llabs(a - r) <= std::llabs(b - r)) { greedy += std::llabs(a - r); a = r; }
        else { greedy += std::llabs(b - r); b = r; }
    }
    std::printf("2 servers, two clusters: OPT %lld, greedy %lld, ratio %.3f\n", opt, greedy, double(greedy) / opt);
}
2 servers, two clusters: OPT 13156, greedy 13156, ratio 1.000

With one cluster per server greedy happens to be optimal; the failure above needed requests between a near server and a far one.

The kk-server conjecture

Conjecture (Manasse, McGeoch and Sleator, 1988). On every metric space, there is a deterministic kk-competitive kk-server algorithm.

By the lower bound this would be best possible. What is known, stated with its conditions:

Setting Best deterministic ratio known Reference
uniform metric (paging) kk, tight Sleator and Tarjan, 1985
k=2k = 2, every metric 22, tight Manasse, McGeoch and Sleator, 1990
metrics with exactly k+1k + 1 points kk, tight Manasse, McGeoch and Sleator, 1990
the line, and trees kk, tight (double coverage) Chrobak, Karloff, Payne and Vishwanathan, 1991; Chrobak and Larmore, 1991
every metric, first finite bound a function of kk only (exponential) Fiat, Rabani and Ravid, 1990
every metric 2k−12k - 1 (work-function algorithm) Koutsoupias and Papadimitriou, 1995

For general metrics the gap between kk and 2k−12k - 1 is open. The work-function algorithm is conjectured to be kk-competitive itself, and it is known to be kk-competitive in several special cases (The Work-Function Algorithm). The randomized version of the conjecture, that O(log⁡k)O(\log k) is achievable against an oblivious adversary on every metric, was refuted in 2023 (Randomized k-Server).

Test yourself

Which special case of the kk-server problem is paging?

  1. The line
  2. The uniform metric, all distances 1
  3. A tree with kk leaves
  4. The Euclidean plane

In the lower-bound proof, how many of the kk offline algorithms pay at each request?

  1. None
  2. Exactly one, and it pays d(rt−1,rt)d(r_{t-1}, r_t)
  3. All kk
  4. Half of them

Why is the greedy rule (move the closest server) not competitive?

  1. It moves too many servers
  2. Requests alternating between two nearby points next to one server make it pay every time, while OPT moves a far server once
  3. It is randomized
  4. It is kk-competitive

What is the status of the deterministic kk-server conjecture on general metrics?

  1. Proved: kk on every metric
  2. Open: the best known general bound is 2k−12k - 1, and kk is a lower bound
  3. Refuted in 2023
  4. Only known for k=1k = 1