lmcache-l2-sim
An L2 adapter for LMCache MP that models a large L2 tier without spending the
disk. It wraps the stock fs (or fs_native) adapter and adds two things:
- Dedup. Writes run through the inner adapter unchanged. When a store completes, each file it wrote is replaced by a hardlink (or symlink) to one canonical file of the same byte size. Every key keeps its own filename and its true apparent size; the tier holds one block of real bytes per distinct block size.
- Latency. Store and load completions can be delayed by a fixed amount, a per-MiB amount, or both, with optional seeded jitter.
This is for capacity modelling and diagnostics, not production. An L2 read
returns the canonical block for the key's size, which is a structurally valid
block but not the KV that was stored under that key. Anything that checks KV
contents (for example lmcache bench server --url ... checksum verification)
will fail for data served from L2, and a model fed these blocks would produce
wrong output.
Developed against LMCache v0.5.8.
Use it out of tree
No LMCache changes or image rebuild needed. Make the package importable by the
server, then select it through LMCache's built-in plugin adapter type.
pip install lmcache-l2-sim # into the environment LMCache runs in
pip install ./plugins/lmcache-l2-sim # or from a clone, from the repo root
# or, without installing: mount this directory and set PYTHONPATH to it
lmcache server ... --l2-adapter '{
"type": "plugin",
"module_path": "lmcache_l2_sim.l2_sim_adapter",
"class_name": "L2SimAdapter",
"adapter_params": {
"inner": {"type": "fs", "base_path": "/data/l2"},
"read_delay_ms": 5
}
}'
Parameters
All go in adapter_params. Only inner is required.
| field | default | meaning |
|---|---|---|
inner |
required | spec of the wrapped adapter, with its own type |
dedup |
true |
collapse stored files onto one canonical file per byte size; false gives latency only |
link_mode |
"hardlink" |
"hardlink" or "symlink" |
canonical_dir |
<base_path>/.dedup |
where canonical files live |
write_delay_ms |
0 |
fixed delay added to each store completion |
write_delay_ms_per_mb |
0 |
store delay per MiB written |
read_delay_ms |
0 |
fixed delay added to each load completion |
read_delay_ms_per_mb |
0 |
load delay per MiB read |
delay_jitter |
0 |
fraction in [0, 1]; each delay is scaled by a uniform factor in [1 - jitter, 1 + jitter] |
seed |
0 |
seed for the jitter stream |
Notes:
- Hardlinks look exactly like real files:
ls -lshows the true size andducounts the content once. Symlinks make the sharing visible, at the cost ofls -lshowing a link. Symlink targets are relative, so they resolve the same from inside a container and from the host. - Hardlinks need
canonical_diron the same filesystem as the innerbase_path, which the default guarantees. - Dedup is per byte size. A run with mixed block sizes keeps one canonical file per size.
- Dedup needs an inner adapter with a
base_path(fsorfs_native). Withdedup: falsethe adapter wraps any inner adapter for latency only. - A delay is added to the completion LMCache observes; the underlying I/O runs at its own pace. Lookups are not delayed.
- Usage and eviction accounting are the inner adapter's, so LMCache sees logical bytes as if nothing were deduplicated.
GET /statuson the server reports the adapter's counters underdedup: files collapsed, bytes saved, collapse errors, completions currently held.
Tests
The tests need LMCache importable, so they run inside an image that has it:
make test-plugins # from the repo root
or directly:
docker run --rm -v "$PWD/plugins:/plugins:ro" -e HOME=/tmp \
-e PYTHONPATH=/plugins/lmcache-l2-sim --entrypoint "" \
lmcache-fleet-demo/lmcache:0.5.8-cpu \
/opt/venv/bin/python -m pytest /plugins/lmcache-l2-sim/tests -q
They cover config parsing and rejection, the plugin loader's config-class discovery, adapter-type registration, the delay arithmetic including jitter bounds, and the collapse itself: hardlink and symlink modes, per-size separation, idempotence, missing files, and the reported counters.
Upstreaming
The module is written to drop into LMCache unchanged, modelled on the in-tree
fault_inject adapter: copy lmcache_l2_sim/l2_sim_adapter.py to
lmcache/v1/distributed/l2_adapters/. It already registers itself as adapter
type dedup, so in tree the spec is simply
{"type": "l2_sim", "inner": {...}, ...}. The in-tree change would also need
the module added to the factory's lazy-import list, and tests.
Metadata
Release files for lmcache-l2-sim 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| lmcache_l2_sim-0.1.0.tar.gz | 20.6 kB | Without provenance | Details for lmcache_l2_sim-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| lmcache_l2_sim-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for lmcache_l2_sim-0.1.0-py3-none-any.whl |
Total release size: 36.8 kB
Release files / lmcache_l2_sim-0.1.0.tar.gz
| Download URL | lmcache_l2_sim-0.1.0.tar.gz |
|---|---|
| Size | 20.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
526d5ca3e0a53bf0ac677caafec52c48d092cb4430bc55437cb955c0e13c9451
|
|
BLAKE2b-256 checksum How to use checksums |
65a939bc4fcfb0c431748e07aa2f98617e7570c8322585ef9353f1c2fef35b03
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.15
|
Release files / lmcache_l2_sim-0.1.0-py3-none-any.whl
| Download URL | lmcache_l2_sim-0.1.0-py3-none-any.whl |
|---|---|
| Size | 16.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3886efe77ed89a22c46faab73ee88b8ed85a304817d17a1ac800d467d29bd166
|
|
BLAKE2b-256 checksum How to use checksums |
6b20518c4cb6cc1d3afaf1f91fc203f76c735f2c508b53a04da8a5982ed33018
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.15
|
Security for lmcache-l2-sim 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.