Caching — Mechanisms, Numbers, Trade-offs
Deep-dive page: the three caching layers in LibreSocial and what measurements say about them.
Sources in order of authority: current code (
com.p2pframework.storagedispatcher,com.p2pframework.datacollection) first; the dedicated caching-structures paper (IEEE ISNCC 2020) supersedes earlier ad-hoc caching notes; Masinde's dissertation (2020) repeats the same numbers in chapter form.
Three caching layers
- Transport/storage cache (LRU, JVM-managed). The signed storage dispatcher keeps a
Least-Recently-Used cache built on Java
SoftReferences with a configurable maximum age of cached items, so the JVM can reclaim memory under pressure (PG 2013 report). Early capacity experiments configured a 200 MB cache plus a 20-entry provider list for redirected lookups (PG 2012, see load balancing). - Overlay-level DHT cache (Pastry/PAST routing and object caches) — implicit, not application-aware; measured as "current cache" below.
- Social caching (push-based, 2020). Instead of pull-on-miss, content updates are pushed to a selected set of peers ("social updates") along instance channels; peers subscribe to up to 150 contacts (Dunbar bound) across 15 update channels (ISNCC 2020).
Selection strategies (ISNCC 2020, Facebook'09 trace, 64 instances / 8 machines, 50 s updates)
| Strategy | Cache-hit ratio | Cost profile |
|---|---|---|
| random | 94.9 % | cache and subscriptions grow continuously — poor scaling |
| trend | 93.3 % | middle ground |
| social score (α·tie strength + β·mutual interest, Dunbar-based) | 92.4 % | smallest cache, fewest subscriptions, ~250–400 MB/instance |
Combination results: DHT cache + social cache together reach 99.2 % cache-based retrievals and cut overlay lookups to 0.8 % of requests (DHT cache alone: 94.5 %, social cache alone: 84.9 %). The price is up to 5× more cache objects and the highest message rate at the message dispatcher. A run without any cache aborted after about a quarter of its planned duration due to internal Pastry errors — caches also act as shock absorbers for overlay re-resolution storms.
Consistency argument
Only the social cache guarantees consistency of cached content, because every update is pushed to subscribers; a time-window/pull cache can serve stale data (ISNCC 2020). This is the main reason the dissertation recommends social score + regular cache despite the lower single-strategy hit ratio of social score alone (dissertation).
Supersession & code state
Earlier reports (PG 2012/2013) describe only the LRU/provider-list layer; the 2020 paper adds the
social layer and re-measures everything on the modern wall/profile plugins — treat 2020 numbers
as current. In today's tree the mechanisms live in storagedispatcher (signed cache with max age)
and the datacollection/MUC code paths for social updates; GitLab item #65 "Schneller Zugriff
(Social Caching)" is closed as delivered.
Open work worth doing
- Re-measure the 99.2 % figure under the Docker cluster testbed (work items #108, #131–#133) — the 2020 numbers come from an 8-machine lab, not a reproducible container setup (blog: cluster testing, evaluation benchmarks).
- Make the social-cache memory budget adaptive: 250–400 MB/instance is fine on desktops but not on the weak nodes the capacity manager protects (load balancing).
Related
caching component page · StorageDispatcher · DDS internals · data synchronization