Skip to content

About

Segcache (NSDI '21) studied through its Rust implementation, measured against memcached 1.6. Targets by total effect: shared frequency-RNG atomic on every hit (caps reads at 15 M/s at 8 threads; 53 M/s without), TTL floor (1–7 s TTLs live 1 s), hash index placement (changed: 1.44x objects/byte, 0.68x time/op), write-path scaling.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

segcache-lab

Segcache (Yang, Yue, Rashmi, NSDI '21) studied through its current implementation. Each mechanism is read in source, measured against the paper's claims and against memcached 1.6, and then changed.

The engine under test is the segcache crate in pelikan-io/cache-rs, which pelikan has embedded since its PR #189. The harness drives the engine in-process and memcached as a native process. Nothing is reimplemented: every measurement runs upstream code built from the commits in notes/repos.md.

Results

# question result details
01 What does one object cost, index included, at a fixed memory budget? Both engines store exactly the count derived from their source, at every size and in every config. Segcache's heap overhead is 8 B per object for values up to 512 B, close to the paper's 5 B. Its fixed-size, first-fit two-choice index refuses inserts from 25–55% occupancy, so sizing it to never refuse costs another 32–45 B per object. Index included, segcache's overhead is 40.7–52.8 B per object against memcached's 62.3–482.6 B. At 32 B values it is 16% below memcached tuned with -C -f 1.08. RESULTS · prediction
Total overhead per object, heap and index

Optimization targets, ranked by total effect

Sixteen candidate changes are mapped in Stop 2. Stop 3 ranks them by what they can move overall, not by local cost:

  1. The frequency update on the read path. Every hit below frequency 127 does a fetch_add on one shared word. At 8 threads this caps the cache at 15.2 M gets/s, against 53.2 M/s for the same lookup without the update, and throughput falls from 4 threads to 8. The paper's C artifact draws a random number only above frequency 16 and updates each item at most once per second.
  2. TTL floor. Max-ages of 1–7 s live 1 s, so for short-TTL traffic an object's miss ratio rises 1.5× to 4.5×. Negligible for TTLs of minutes or more.
  3. Index placement and sizing. Least-loaded placement (change 01) holds 1.44× as many objects per byte at 32 B values. It also takes 0.68× the time per operation in a DRAM-sized working set. Exact sizing would raise 64 B values from 1.20× to 1.33×.
  4. Write-path scaling. Replace throughput falls with every thread added, to 0.44× of one thread at 8. This fits the single CAS'd tail per TTL bucket (cache-rs #85), not yet tested here.
  5. Instruction-level work. A get against a DRAM-sized working set is about 81% memory wait. Behind a network the engine is under 3% of server CPU per request.
Throughput by thread count: get peaks at 4 threads

Changes to the engine

Each change is a patch against the pinned cache-rs. Its predictions are committed before it is measured, and it runs through cache-rs's own unit, debug and shuttle suites.

# change result details
01 Least-loaded placement in the hash index, as cache-rs's docs describe First refused insert at 0.71–0.80 load instead of 0.30–0.55. The index needs one power of two fewer slots: 1.44× objects per byte at 32 B values, 1.20× at 64 B, 1.11× at 128 B. A hit costs about 22 more instructions and a new-key insert up to 299 more, yet with a DRAM-sized working set an 80/10/10 mix takes 0.68× the time. All suites pass. RESULTS · patches

Source notes

stop covers file
1 Item, segment and index layout in both engines; paper vs C artifact vs Rust; where cache-rs's docs and code disagree notes/stop-1-layout.md
2 Exact instructions per operation by component and source line; sixteen targets pinned to the structures they live in notes/stop-2-hot-paths.md · target map
3 Amdahl budget: each target judged against memory, misses and CPU; latency, read scaling to 8 threads and network share, timed notes/stop-3-amdahl.md

What you run

make fetch     # clone upstreams at pinned commits, build memcached 1.6.45
make verify    # 13 invariant checks on the model and both engines
make exp01     # experiment 01 end to end, about 8 minutes on an M4 Pro
make vm        # arm64 Linux VM with valgrind, for exact profiles
make cachegrind           # instructions per operation, by component and line
make samply OP=get-miss   # native call stacks in the Firefox Profiler

This needs cargo (the toolchain is pinned in rust-toolchain.toml), a C toolchain, autotools, libevent and python3. The experiment scripts use the Python standard library only. repos/ and papers/dl/ are not committed. notes/repos.md lists every clone with its commit, and papers/README.md gives the paper's URL and SHA-256.

What you get

path contents
notes/ crawl notes on the source, cited file:line at pinned commits
experiments/NN-name/ PREDICTION.md (committed before the run), driver, raw CSVs, RESULTS.md, figures
harness/ Rust crate: capacity (one measurement, one CSV row), predict (the source-derived model), verify, profile (single-operation workloads for profilers)
profiles/ per-build instruction counts: ops.csv, components.csv, lines.csv, annotated source per operation
env/host.md host description, and which experiments it can and cannot support
scripts/ fetch, memcached build, host report

How results are kept honest

  • Every experiment commits its prediction before it runs, and lists any runs made before the prediction was written.
  • The capacity model is code. make verify checks it against the engine's own size function and against the slab table memcached prints.
  • Each point uses five disjoint key sets, because both engines hash with fixed seeds.
  • Corrections stay in the record. Stop 1 originally misread the index size by 8×; the error and how it was caught are in the note and its commit.

Not measured yet

  • Scaling past 8 threads. This host is macOS on Apple silicon, with no core affinity and mixed core types. Stop 3's scaling stops at the 8 performance cores. Wider curves (planned experiment 06) need a Linux host. See env/host.md.
  • Expiry behaviour (02, 03). make verify already pins the TTL bucket floor exactly: a 10 s TTL lives 8 s, and 1–7 s TTLs live 1 s (notes/stop-1-layout.md, harness model.rs). The memory and hit-ratio consequences are not measured yet.
  • Which shared write caps reads. Stop 3 shows the frequency update caps read throughput. Separating the shared RNG word from the slot CAS is change 02.
  • Why writes do not scale. The single tail per TTL bucket is the leading candidate, untested.

Licence

MIT, see LICENSE. Upstream projects keep their own licences; none of their source is in this repository.

About

Segcache (NSDI '21) studied through its Rust implementation, measured against memcached 1.6. Targets by total effect: shared frequency-RNG atomic on every hit (caps reads at 15 M/s at 8 threads; 53 M/s without), TTL floor (1–7 s TTLs live 1 s), hash index placement (changed: 1.44x objects/byte, 0.68x time/op), write-path scaling.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages