Skip to content

Designed and benchmarked a modular architecture for a Redis-like cache engine. Achieved sub-millisecond performance in all core modules (LRU cache, parser, telemetry) with 100% test pass rate except WAL. MMap-based persistence achieved durable snapshot/load in 21 ms.

License

Notifications You must be signed in to change notification settings

SKG24/DistCache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DistCache: Distributed Key-Value Store

Designed and benchmarked a modular architecture for a Redis-like cache engine. Achieved sub-millisecond performance in all core modules (LRU cache, parser, telemetry) with 100% test pass rate except WAL. MMap-based persistence achieved durable snapshot/load in 21 ms. TTL logic tested over real time to ensure correctness. Identified and isolated a fault in WAL replay parsing logic, confirming robustness of test framework.


🧠 Architecture Overview

              +---------------------+         +----------------------+
              |  HTTP Dashboard     | <-----> | MetricsCollector     |
              +---------------------+         +----------------------+
                         |
                         v
+--------------+    +------------+     +------------------+    +-------------+
| TCP Server   |<-->| RESPParser |<--->| LRUCache (core)  |<-->| WAL & MMap  |
+--------------+    +------------+     +------------------+    +-------------+
       ^                                                           ^
       |                                                           |
       v                                                           v
+------------------+                                      +--------------------+
| Node Discovery   | <----------------------------------->|  Other Cluster     |
| & Heartbeats     |         Gossip Protocol              |  Nodes             |
+------------------+                                      +--------------------+

🧩 Components

LRUCache (src/storage/LRUCache.h/.cpp)

  • Thread-safe in-memory cache
  • LRU eviction policy
  • TTL support per key
  • Mutex-protected for concurrency

WAL (Write-Ahead Log)

  • Appends each operation to disk for durability
  • Supports crash recovery
  • Binary & text-based modes with MessagePack

MMapPersistence

  • Snapshots the in-memory state to disk using mmap or file writes
  • Supports loading at startup for fast recovery

TCPServer

  • Simulated TCP server accepting multiple client connections
  • Uses custom RESP-like protocol for command parsing

RESPParser

  • Parses commands like GET, SET, DELETE
  • Serializes responses in Redis protocol-like format

NodeDiscovery

  • Simulated UDP-based heartbeat broadcasting
  • Intended for future cluster awareness and gossip protocol

MetricsCollector

  • Tracks latency, throughput, and ops
  • JSON output for HTTP dashboard

HttpDashboard

  • Simulated dashboard for stats visualization
  • Future: real metrics UI with web sockets

🐳 Docker

docker build -t distcache .
docker run -it distcache

Repo Structure

DistCache/
├── src/
│   ├── storage/        # LRUCache, WAL, MMapPersistence
│   ├── network/        # TCPServer, RESPParser
│   ├── monitoring/     # Metrics, Dashboard
│   └── cluster/        # Discovery, Gossip (simulated)
├── tests/              # Unit tests (Google Test)
├── benchmarks/         # Benchmarking scripts
├── docker/             # Dockerfile, entrypoints
├── CMakeLists.txt      # Main build script
└── README.md

Results

Run_Tests result

[----------] Global test environment tear-down
[==========] 8 tests from 5 test suites ran. (2023 ms total)
[  PASSED  ] 7 tests.
[  FAILED  ] 1 test, listed below:
[  FAILED  ] WALTest.AppendAndReplay

Benchmark result

root@595fa24b7c68:/app/build# ./benchmark/run_benchmark | tee benchmark_results.txt
[Benchmark] Initializing...
[Benchmark] SET throughput: 273306 ops/sec
Latency: 365.89ms
[Benchmark] GET throughput: 897644 ops/sec | Hits: 50000
Latency: 55.7014ms
[Benchmark] JSON Report: {"latency":5.5}
root@595fa24b7c68:/app/build# 

Screenshot 2025-06-28 at 1 00 58 AM

  • Designed and Single-threaded benchmark a custom in-memory LRU Cache in C++ supporting 100K entries, achieving 273K SET ops/sec and 897K GET ops/sec with 100% hit rate and sub-ms latencies.
  • Demonstrated low-latency reads (~1.1µs) and high throughput under 100K operations workload. - 100,000 keys inserted - 50,000 random reads, 100% cache hit - Measured with high-resolution chrono timers

Failure

Since WALTest is failing due to a test race condition, fixing it (via file.close() or adding sleep) will help make your resume even stronger and allow you to claim: 100% passing unit tests in Dockerized test suite.

Screenshot 2025-06-27 at 11 04 17 PM


Conclusion

  • LRUCache - Implementation is performant for basic operations. TTL expiration is verified with deterministic delay.

     - ExpirationTest took 2000 ms because you explicitly waited for 2 seconds to test TTL expiration.
    
     - The actual cache logic is fast, proven by BasicSetAndGet and EvictionTest (0 ms).
    
  • Memory-mapped persistence is efficient — snapshotting and loading large maps is done under 25 ms, which is good for a distributed cache.

  • MetricsCollector - Operation recorded and JSON generated in 0 ms.

     - Ideal for real-time monitoring. The latency tracking system is lightweight and fast.
    
  • RESPParser

     - Parsing and serialization are both instantaneous (0 ms).
    
     - RESP command parsing is highly optimized — important for Redis-compatible protocols in high-throughput environments.
    
  • WALTest

     - Shows 0 ms but failed — replay() didn't return expected ops.
    
     - While the time was negligible, the functionality failed. Likely due to incorrect parsing (e.g., handling of DEL with missing value), or log format inconsistency.
    

About

Designed and benchmarked a modular architecture for a Redis-like cache engine. Achieved sub-millisecond performance in all core modules (LRU cache, parser, telemetry) with 100% test pass rate except WAL. MMap-based persistence achieved durable snapshot/load in 21 ms.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published