The Ultra-High Performance, Zero-Copy In-Memory Engine for Redis-Compatible Caching & LLM KV-Cache Offloading
KacheDB is an open-source, next-generation in-memory engine engineered from first principles in Rust. It unifies microsecond-latency application caching with high-throughput LLM tensor memory management in a single zero-copy architecture:
- β‘ Microsecond App Cache: Wire-compatible Redis & Valkey engine (RESP2 / RESP3 wire protocol) powered by an AVX-512 / NEON SIMD Swiss Table, an explicit 2 MB Megaslab bump allocator, S3-FIFO eviction, and strictly bounded
$\mathcal{O}(1)$ timing wheels. - π Keyspace & Hash Cursor Scanning: Non-blocking
SCANandHSCANcursor iteration across 256 shards using home-bucket bit-reversed cursors, zero-allocation glob pattern matching (*,?,[...]), ReDoS backtracking protection, and 40-byte inline Short String Optimization (SSO). - π€ LLM KV-Cache Offloader: Hierarchical
&[u32]token prefix tree and zero-copy POSIX Shared Memory (/dev/shm) lock-free SPSC ring buffers for vLLM, SGLang, and PyTorch (17.6M msgs/sec, sub-50ns tensor sharing, 0 socket copies). - π Encrypted ACID Durability: Append-Only File (AOF) and Snapshot Format V7 (
KDB\x07) with streaming hardware-acceleratedAES-256-GCMorChaCha20-Poly1305encryption-at-rest.
| Feature / Metric | Redis 7.4 | Valkey 8.0 | DragonflyDB | KacheDB v0.4 |
|---|---|---|---|---|
| Language | C | C | C++ | Rust π¦ |
| Peak GET Throughput | 964,654 QPS | 1,033,849 QPS | 2,296,822 QPS | 3,563,603 QPS π |
| Peak SET Throughput | 924,900 QPS | 989,303 QPS | 2,047,948 QPS | 3,217,341 QPS π |
| Mixed 80/20 QPS | 940,532 QPS | 966,189 QPS | 2,009,829 QPS | 3,524,141 QPS π |
| P50 Tail Latency | 3.25 ms | 3.09 ms | 1.31 ms | 0.70 ms π |
| Peak Memory (RSS) | 1,001 MiB | 932 MiB | 1.05 GiB | 871.4 MiB π |
| Memory Architecture |
jemalloc / Heap |
jemalloc / Heap |
Custom Slab | 2 MB Megaslab (Bump + Free-list + Compaction) |
| Hot-Path Alloc Overhead | 20β50 ns | 20β50 ns | 10β25 ns | 3.84 ns ($\mathcal{O}(1)$) |
| Hash Indexing | Dict / Chained Hash | Dict / Chained Hash | dashtable |
AVX-512 / NEON Swiss Table |
| Keyspace Cursor Scan | Bucket bit-reversed | Bucket bit-reversed | Segmented scan | Home-Bucket Bit-Reversed (256 Shards, ReDoS-Safe Glob) |
| Lookup Hit Latency | 15β30 ns | 15β30 ns | 8β15 ns | 1.96 ns (L1 Cache Line) |
| Async Network Engine |
epoll / kqueue
|
epoll / kqueue
|
epoll fiber pool |
Accept-Dispatch epoll + TCP_NODELAY |
| TTL Expiration Engine | Probabilistic Sampling | Probabilistic Sampling | Active Scanning | |
| Durability & Snapshots | RDB / AOF | RDB / AOF | Snapshot | Snapshot V7 (KDB\x07) + AOF + AEAD Encryption |
| LLM KV-Cache Prefix Tree | β None | β None | β None | β
Native &[u32] Token Radix |
| Zero-Copy PyTorch IPC | β TCP Socket Serialization | β TCP Socket Serialization | β TCP Socket | β
/dev/shm Lock-Free Ring |
docker run --privileged --ipc host -p 6379:6379 -d --name kachedb ghcr.io/vubon/kachedb:latestgit clone https://github.com/vubon/kachedb.git && cd kachedb
docker compose -f docker/docker-compose.yml up -d --buildcargo build --release --workspace
# Start multi-worker daemon with canonical config
./target/release/kachedb-server -c kachedb.conf
# Or override via CLI flags directly
./target/release/kachedb-server -p 6379 -w 4$ redis-cli -p 6379 SET user:100 "alice" EX 60
OK
$ redis-cli -p 6379 GET user:100
"alice"
$ redis-cli -p 6379 HSET user:100:profile name "alice" role "admin"
(integer) 2
$ redis-cli -p 6379 HGET user:100:profile name
"alice"
$ redis-cli -p 6379 SCAN 0 MATCH "user:*" COUNT 10
1) "0"
2) 1) "user:100"
2) "user:100:profile"
$ redis-cli -p 6379 HSCAN user:100:profile 0 MATCH "r*"
1) "0"
2) 1) "role"
2) "admin"
$ redis-cli -p 6379 TYPE user:100:profile
hash
$ redis-cli -p 6379 DBSIZE
(integer) 2KacheDB implements the standard RESP2 / RESP3 binary wire protocol. You can use any existing Redis or Valkey client library (redis-py, ioredis, go-redis, redis-rs, jedis) without code modifications:
| Command | Syntax | Description | Time Complexity |
|---|---|---|---|
PING |
PING [message] |
Tests server liveness; returns PONG or echoed message. |
|
SET |
SET key value [EX seconds] [PX millis] |
Stores binary value with optional high-resolution TTL expiration. | |
GET |
GET key |
Retrieves binary value, returning nil if missing or expired. |
|
MSET |
MSET key value [key value ...] |
Atomically stores multiple key-value pairs. | |
MGET |
MGET key [key ...] |
Batch retrieves multiple keys in a single pipelined operation. | |
DEL |
DEL key [key ...] |
Removes keys and immediately returns slab slots to the free-list. | |
EXISTS |
EXISTS key [key ...] |
Returns the count of existing, unexpired keys. | |
INCR / DECR |
INCR key / DECR key
|
Increments or decrements string integer value by 1. | |
INCRBY / DECRBY |
INCRBY key delta / DECRBY key delta
|
Atomically adds/subtracts integer delta to/from value. | |
APPEND |
APPEND key value |
Appends value to existing string, returning new byte length. | |
STRLEN |
STRLEN key |
Returns byte length of string value (0 if missing). |
| Command | Syntax | Description | Time Complexity |
|---|---|---|---|
HSET |
HSET key field value [f v ...] |
Sets field-value pairs in hash; returns count of newly added fields. | |
HGET |
HGET key field |
Retrieves field value in hash (< 25 ns L1 CPU cacheline probe). | |
HDEL |
HDEL key field [field ...] |
Removes field(s) from hash; deletes key when empty. | |
HEXISTS |
HEXISTS key field |
Checks if field exists in hash (returns 1 or 0). | |
HLEN |
HLEN key |
Returns the number of live fields in the hash. | |
HGETALL |
HGETALL key |
Returns all fields and values in the hash as a flat array. |
| Command | Syntax | Description | Time Complexity |
|---|---|---|---|
SCAN |
SCAN cursor [MATCH pattern] [COUNT count] [TYPE type] |
Incrementally iterates the keyspace across 256 shards with zero heap allocations. |
|
HSCAN |
HSCAN key cursor [MATCH pattern] [COUNT count] |
Iterates through fields and values within a hash using glob pattern matching. |
|
| Command | Syntax | Description | Time Complexity |
|---|---|---|---|
DBSIZE |
DBSIZE |
Returns the total count of keys in the current database. | |
TYPE |
TYPE key |
Returns key data type (string, hash, vector, or none). |
|
EXPIRE / TTL |
EXPIRE key seconds / TTL key
|
Configures and queries key TTL lifecycle in |
|
PERSIST |
PERSIST key |
Removes TTL expiration, making key persistent. | |
FLUSHDB |
FLUSHDB |
Clears all keys and recycles slab pool memory blocks. | |
FLUSHALL |
FLUSHALL |
Clears all keys across all database instances. | |
BGREWRITEAOF |
BGREWRITEAOF |
Compacts the append-only file in the background when AOF is enabled. | β |
INFO |
INFO [section] |
Returns real-time telemetry, memory stats, and keyspace diagnostics. | |
QUIT |
QUIT |
Closes the client connection gracefully. | |
COMMAND |
COMMAND DOCS |
Returns Redis protocol capability metadata. |
Binary-Safe Storage: All keys and values are treated as raw byte slices (
&[u8]). Store JSON strings, raw binary tensors, Protobuf buffers, images, or compressed blobs up to 2 MB per slot without encoding overhead.
+-----------------------------------------------------------------------------------------------+
| CLIENT INTERFACES |
| [RESP3 Wire Protocol (Redis/Valkey Clients)] [Zero-Copy Tensor IPC / Python SDK] |
+-----------------------------------------------------------------------------------------------+
|
+-----------------------------------------------------------------------------------------------+
| INDEXING SUBSYSTEM |
| 1. SIMD Swiss Hash Table (1.96 ns Point Lookups, 256 Shards, S3-FIFO Eviction Tracking) |
| 2. Keyspace Scanning (Bit-Reversed Radix Cursors, ReDoS-Safe Zero-Alloc Glob Matching) |
| 3. Token Radix Prefix Tree (&[u32] Longest Prefix Match for LLM KV-Cache Prefills) |
| 4. Per-Core Hashed Timing Wheel (3,600 Circular Buckets for O(1) Memory Reclamation) |
+-----------------------------------------------------------------------------------------------+
|
+-----------------------------------------------------------------------------------------------+
| CORE SLAB & ARENA ENGINE |
| - 2 MB Megaslab Page Frames (64-byte Cache-Line Aligned Slots, 0 False Sharing) |
| - Zero Runtime Heap Allocation Jitter (Bump-pointer + Free-list Recycling) |
| - Dynamic S3-FIFO Workload Quota Manager (App Cache vs Tensor Cache Elastic Pool) |
+-----------------------------------------------------------------------------------------------+
|
+-----------------------------------------------------------------------------------------------+
| STORAGE & ZERO-COPY TRANSPORT |
| - POSIX Shared Memory (/dev/shm) Lock-Free SPSC Ring Buffer IPC (17.66M msgs/sec) |
| - Accept-Dispatch Thread-per-Core TCP Engine (epoll + TCP_NODELAY / mio) (3.56M QPS) |
| - Encrypted Durability (AOF + Snapshot V7 KDB\x07 with AES-256-GCM / ChaCha20) |
+-----------------------------------------------------------------------------------------------+
Environment: Docker Linux (Isolated 4 CPUs, 4 GB RAM per container), memtier_benchmark (50 clients, 4 threads, 16 pipeline, 64-byte value)
| Storage Engine | SET (Writes/sec) | GET (Reads/sec) | Mixed 80/20 (QPS) | Latency P50 (ms) | Latency P99 (ms) | Peak RAM (RSS) |
|---|---|---|---|---|---|---|
| REDIS 7.4 | 924,900.44 | 964,653.69 | 940,532.39 | 3.25 ms | 5.57 ms | 1,001 MiB |
| VALKEY 8.0 | 989,302.62 | 1,033,848.62 | 966,188.94 | 3.09 ms | 5.15 ms | 932 MiB |
| DRAGONFLY | 2,047,947.57 | 2,296,821.72 | 2,009,828.87 | 1.31 ms | 3.78 ms | 1.05 GiB |
| KACHEDB π | 3,217,341.21 | 3,563,602.65 | 3,524,140.89 | 0.70 ms | 3.54 ms | 871.4 MiB π |
All micro-benchmarks evaluated with Criterion.rs in release mode (opt-level = 3):
| Subsystem | Operation | Measured Latency | Throughput / Hardware Metric |
|---|---|---|---|
kachedb-core |
Megaslab Slot Allocation (AppSmall 128 B) |
3.94 ns | Flat |
kachedb-core |
Multi-Arena Pool Allocate + Free (AppSmall) |
11.97 ns | Elastic quota-safe allocation |
kachedb-hash |
Swiss Table Point Query Hit (1M keys) | 1.96 ns | 510.2 Million lookups/sec / core |
kachedb-hash |
Swiss Table 1M Keys Sequential Insert | 25.85 ms | β44.5% speedup via tombstone compaction |
kachedb-hash |
Zero-Alloc Glob Pattern Matching (prefix*) |
4.21 ns | Linear single-star fast-path (ReDoS immune) |
kachedb-radix |
1,024-token Prompt Prefix Match (64 blocks) | 2.48 Β΅s | ~10,000Γ speedup vs GPU prefill |
kachedb-radix |
Bottom-up LRU Leaf Eviction | 403.1 ns | Sub-microsecond tensor memory reclaim |
kachedb-shm |
POSIX Shared Memory Push/Pop Roundtrip | 83.18 ns / msg | 12.0 Million msgs/sec (single-thread) |
kachedb-proto-resp |
Streaming Zero-Alloc RESP GET Decoding |
86.17 ns | Zero heap allocations on borrowed slice |
kachedb-net |
Accept-Dispatch TCP Engine (Linux epoll) | 0.70 ms (P50) | 3.56 Million QPS (Docker Linux) |
kachedb-net |
macOS mio / kqueue TCP (4 Workers, 100 Clients) |
16 Β΅s (P50) | 4.32 Million SET/s, 3.92M GET/s |
kachedb/
βββ crates/
β βββ kachedb-core/ # 64-byte aligned Megaslab allocator, SlabPool & HashedTimingWheel
β βββ kachedb-hash/ # SIMD Swiss Table, bit-reversed SCAN, ReDoS-safe glob, S3-FIFO & inline SSO
β βββ kachedb-radix/ # Token prefix tree with lock-free EpochTree RCU concurrency
β βββ kachedb-vector/ # SIMD vector indexing, SQ8 quantization & HNSW search
β βββ kachedb-proto-tensor/ # 64-byte TensorBlockDescriptor & PagedAttention layouts
β βββ kachedb-shm/ # Zero-copy POSIX /dev/shm SPSC ring buffer IPC
β βββ kachedb-proto-resp/ # Zero-allocation streaming RESP2/RESP3 wire parser
β βββ kachedb-net/ # Thread-per-core async TCP engine (io_uring / mio) with non-blocking SCAN
β βββ kachedb-server/ # Multi-core daemon runtime executable with Snapshot V7 & AOF
β βββ kachedb-cli/ # Interactive CLI admin, REPL & KDB\x07 forensic inspection tool
β βββ kachedb-bench/ # Standalone multi-connection pipelined load generator
βββ bindings/
β βββ python/ # Zero-copy Python client (scan_iter, hscan_iter, PyTorch & vLLM IPC)
βββ docs/
β βββ commands/ # Complete command references (core-kv, hashes, scanning, vector)
β βββ architecture/ # Deep dive architecture specifications
β βββ rfcs/ # Formal Architecture Decision Records (ADRs)
β βββ benchmarks/ # Standardized benchmark reproduction protocol
βββ docker/ # One-command reproducible Linux io_uring container
from kachedb import KacheClient
# Connect to KacheDB daemon over TCP
with KacheClient(host="127.0.0.1", port=6379) as client:
# 1. Standard Redis-compatible caching with TTL
client.set("session:user_1", "active_payload", ex=3600)
print("Session:", client.get("session:user_1"))
# 2. Redis Hash operations
client.hset("user:1:profile", mapping={"name": "Alice", "role": "admin"})
print("Role:", client.hget("user:1:profile", "role"))
# 3. Streaming keyspace iteration with zero-allocation generator
for key in client.scan_iter(match="session:*", count=50):
print("Discovered key:", key.decode("utf-8"))
# 4. Streaming Hash iteration
for field, val in client.hscan_iter("user:1:profile", match="*"):
print(f"Field: {field.decode('utf-8')} -> {val.decode('utf-8')}")
# 5. Zero-copy KV-cache tensor extraction from /dev/shm (< 50 ns, 0 bytes copied)
tensor = client.read_tensor_zero_copy(core_id=0, byte_offset=0)
print("Zero-copy PyTorch Tensor Shape:", tensor.shape)Complete documentation, command references, and integration guides are available in the docs/ directory:
- π Quickstart Guide & kachedb-cli Manual
- βοΈ Server Configuration & Tuning
- π Core Key-Value Command Reference
- π¦ Redis Hash Primitives Guide
- π Keyspace & Hash Cursor Scanning (
SCAN,HSCAN) - β±οΈ TTL & Key Expiration Lifecycle
- π§ SIMD Vector Search Commands
- π Server Observability & Introspection
- ποΈ System Architecture Overview
- π Snapshot Encryption-at-Rest
- π€ vLLM, SGLang, Semantic Caching, and Antigravity IDE Guides
To reproduce our performance benchmarks in an isolated Linux environment:
# Run one-command reproducible benchmark suite inside Docker
make benchmark-reproduceFor hardware specifications and step-by-step instructions, see docs/benchmarks/reproducibility.md.
We welcome contributions from systems and AI infrastructure engineers! Please review:
Dual-licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.