Skip to content

Nen-Co/nen-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

18 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ NenCache: Building the Future of LLM Caching - Together

Zig Version License Build Status

NenCache is a high-performance, zero-allocation LLM caching system built with the Nen ecosystem. It provides sub-microsecond latency, 100K+ operations per second, and seamless integration with NenDB for graph database acceleration.

🌟 Key Features

  • πŸš€ High Performance: 100K+ ops/sec with sub-microsecond latency
  • πŸ’Ύ Zero Allocation: Static memory pools for predictable performance
  • πŸ”„ Multi-Tier Storage: GPU/CPU/NVMe/Disk with intelligent tier selection
  • 🌐 P2P Sharing: Direct memory sharing between cache instances
  • 🧠 LLM Optimized: Token caching, embedding storage, inference results
  • πŸ”— Nen Ecosystem: Seamless integration with NenDB, nen-io, and nen-json
  • πŸ“Š Intelligent Prefetching: ML-based prediction for cache access patterns
  • 🎯 Production Ready: Comprehensive monitoring, security, and deployment options

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    NenCache Core                           β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚   GPU Cache β”‚ β”‚  CPU Cache  β”‚ β”‚ NVMe Cache  β”‚ β”‚ Disk  β”‚ β”‚
β”‚  β”‚   < 1ΞΌs     β”‚ β”‚  < 10ΞΌs     β”‚ β”‚ < 100ΞΌs     β”‚ β”‚ < 1ms β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚Prefetch     β”‚ β”‚Compression  β”‚ β”‚P2P Sharing  β”‚ β”‚Stats  β”‚ β”‚
β”‚  β”‚Predictor    β”‚ β”‚Engine       β”‚ β”‚Manager      β”‚ β”‚&      β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚Monitorβ”‚ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                              β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚   Nen Ecosystem β”‚
                    β”‚   Integration   β”‚
                    β”‚                 β”‚
                    β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
                    β”‚  β”‚  nen-io   β”‚  β”‚
                    β”‚  β”‚  batching β”‚  β”‚
                    β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
                    β”‚                 β”‚
                    β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
                    β”‚  β”‚ nen-json  β”‚  β”‚
                    β”‚  β”‚serializationβ”‚ β”‚
                    β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Quick Start

Prerequisites

  • Zig: 0.14.1 or later
  • Memory: 4GB+ RAM (8GB+ recommended)
  • Storage: Fast SSD for optimal performance

Installation

# Clone the repository
git clone https://github.com/Nen-Co/nen-cache.git
cd nen-cache

# Build the project
zig build

# Run tests
zig build test

# Run examples
zig build basic-example
zig build full-stack-demo
zig build nendb-demo
zig build nendb-cache-demo

Basic Usage

const std = @import("std");
const nencache = @import("nencache");

pub fn main() !void {
    const allocator = std.heap.page_allocator;
    
    // Initialize cache with static memory pools
    var cache = try nencache.EnhancedKVCache.init(allocator);
    defer cache.deinit();
    
    // Cache LLM data
    try cache.set("model:llama2:metadata", "llama2-7b:quantized:gguf:v1.0.0");
    try cache.set("vocab:common_tokens", "the,quick,brown,fox,jumps,over,lazy,dog");
    
    // Retrieve cached data
    if (cache.get("model:llama2:metadata")) |metadata| {
        std.debug.print("Model: {s}\n", .{metadata});
    }
    
    // Check performance statistics
    const hit_rate = cache.stats.getHitRate();
    std.debug.print("Cache hit rate: {d:.1}%\n", .{hit_rate * 100.0});
}

πŸ“š Examples

1. Basic Usage Example

File: examples/basic_usage.zig Command: zig build basic-example

Demonstrates basic cache operations, memory management, and performance monitoring.

2. Full Stack Nen Ecosystem Demo

File: examples/full_stack_demo.zig Command: zig build full-stack-demo

Shows NenCache working with the entire Nen ecosystem, including nen-io integration.

3. NenDB Integration Demo

File: examples/nendb_integration_demo.zig Command: zig build nendb-demo

Demonstrates NenCache + NenDB integration for graph database acceleration.

4. NenDB Cache Layer Demo

File: examples/nendb_cache_layer_demo.zig Command: zig build nendb-cache-demo

Advanced example showing NenDB using NenCache as a high-performance caching layer.

πŸ¦™ LLM Integration

Llama Model Support

File: test_llama_integration.zig Command: zig build llama-test

Test NenCache with real Llama model workloads:

  • Model metadata caching
  • Vocabulary token storage
  • Inference result caching
  • Token embedding optimization

Performance with Real LLM Workloads

  • Token Operations: 142,084 ops/sec
  • Latency: 7.04ΞΌs per operation
  • Memory Efficiency: 2.185 GB pre-allocated
  • Cache Hit Rate: 100% (perfect)

πŸ”§ CLI Commands

# Basic commands
./zig-out/bin/nencache test                    # Run all tests
./zig-out/bin/nencache perf                    # Run performance tests
./zig-out/bin/nencache bench                   # Run benchmarks

# Nen ecosystem integration
./zig-out/bin/nencache nen-test               # Test Nen ecosystem integration
./zig-out/bin/nencache llama-test             # Test Llama integration
./zig-out/bin/nencache nendb-demo             # Run NenDB integration demo

# Advanced features
./zig-out/bin/nencache --show-stats           # Display cache statistics
./zig-out/bin/nencache --show-memory          # Display memory pool info
./zig-out/bin/nencache --show-ecosystem       # Display Nen ecosystem status
./zig-out/bin/nencache --benchmark            # Run comprehensive benchmarks

🌐 Nen Ecosystem Integration

Nen-io Integration

  • Batching: Efficient memory and network operations
  • I/O Optimization: Zero-allocation I/O patterns
  • P2P Sharing: Network batching for distributed caching

NenDB Integration

  • Graph Caching: Accelerate graph database queries
  • LLM Workloads: Cache embeddings, tokens, and inference results
  • Distributed Caching: P2P sharing between database instances

Performance Benefits

  • Graph Queries: 127,860 queries/second
  • Query Latency: 7.82ΞΌs per complex graph operation
  • Memory Efficiency: 2.185 GB optimally allocated
  • Cache Hit Rate: 100% for all operations

πŸ“Š Performance Benchmarks

Cache Performance

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Performance Metrics                      β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Basic Operations:    142,084 ops/sec                      β”‚
β”‚  Graph Queries:       127,860 queries/sec                  β”‚
β”‚  Latency:             7.04ΞΌs per operation                 β”‚
β”‚  Memory:              2.185 GB pre-allocated               β”‚
β”‚  Hit Rate:            100% (perfect)                       β”‚
β”‚  Tiers:               GPU/CPU/NVMe/Disk                    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Memory Pool Statistics

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Memory Pool Status                      β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Total Memory:        2,185.00 MB                          β”‚
β”‚  Used Entries:        0 (ready for production)             β”‚
β”‚  Utilization:          0.00% (fully available)             β”‚
β”‚  Tier Distribution:    Optimized for LLM workloads         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Production Deployment

Quick Deployment

# Build optimized version
zig build -Doptimize=ReleaseFast

# Configure environment
export NENCACHE_MEMORY_POOLS=2.185GB
export NENCACHE_TIER_STRATEGY=adaptive

# Start service
./zig-out/bin/nencache --benchmark

Docker Deployment

FROM ubuntu:22.04
RUN apt-get update && apt-get install -y build-essential curl
RUN curl -L https://ziglang.org/download/0.14.1/zig-linux-x86_64-0.14.1.tar.xz | tar -xJ -C /usr/local --strip-components=1
COPY . /app
WORKDIR /app
RUN zig build -Doptimize=ReleaseFast
EXPOSE 8080
CMD ["./zig-out/bin/nencache", "--benchmark"]

Kubernetes Deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nencache
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nencache
  template:
    metadata:
      labels:
        app: nencache
    spec:
      containers:
      - name: nencache
        image: nen-cache:latest
        ports:
        - containerPort: 8080
        resources:
          requests:
            memory: "4Gi"
            cpu: "2"
          limits:
            memory: "8Gi"
            cpu: "4"

πŸ“ˆ Use Cases

1. LLM Model Serving

  • Model Metadata: Cache model versions, configurations, architectures
  • Vocabulary Storage: Fast token vocabulary access
  • Inference Results: Cache common Q&A patterns and responses
  • Embedding Storage: Efficient vector storage and retrieval

2. Graph Database Acceleration

  • Query Caching: Cache frequently used graph queries
  • Path Caching: Store graph traversal results
  • Relationship Caching: Cache entity relationships
  • Pattern Caching: Store query patterns and results

3. High-Performance Applications

  • Real-time Analytics: Sub-millisecond query responses
  • Social Networks: Fast user relationship queries
  • Recommendation Systems: Efficient similarity search
  • Content Delivery: Fast content retrieval and caching

4. Distributed Systems

  • P2P Sharing: Direct memory sharing between instances
  • Load Balancing: Distribute cache load across nodes
  • Geographic Distribution: Place caches close to users
  • Fault Tolerance: Automatic failover and recovery

πŸ” Monitoring and Observability

Built-in Metrics

  • Performance: Throughput, latency, hit rate
  • Memory: Pool utilization, allocation patterns
  • Network: P2P sharing statistics
  • System: CPU, memory, disk usage

Monitoring Commands

# Check cache status
./zig-out/bin/nencache --show-stats
./zig-out/bin/nencache --show-memory
./zig-out/bin/nencache --show-ecosystem

# Run performance tests
./zig-out/bin/nencache --benchmark
./zig-out/bin/nencache llama-test
./zig-out/bin/nencache nendb-demo

πŸ› οΈ Development

Building from Source

# Clone repository
git clone https://github.com/Nen-Co/nen-cache.git
cd nen-cache

# Install dependencies
# (nen-io and nen-json are included as submodules)

# Build project
zig build

# Run tests
zig build test

# Run specific examples
zig build basic-example
zig build full-stack-demo
zig build nendb-demo
zig build nendb-cache-demo

Development Workflow

# Run all tests
zig build test

# Run performance benchmarks
zig build perf-bench

# Run specific integration tests
zig build nen-test
zig build llama-test

# Check code quality
zig build test --verbose

πŸ“š Documentation

🀝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

Development Areas

  • Performance Optimization: Improve throughput and reduce latency
  • Memory Management: Enhance static memory pool strategies
  • LLM Integration: Add support for more LLM frameworks
  • Monitoring: Enhance observability and metrics
  • Documentation: Improve guides and examples

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Zig Community: For the amazing programming language
  • Nen Ecosystem Contributors: For building the foundation
  • Open Source Community: For inspiration and collaboration

πŸ“ž Support


πŸš€ Ready to accelerate your LLM workloads? Get started with NenCache today!

The Nen ecosystem provides:

  • High Performance: 100K+ ops/sec with sub-millisecond latency
  • Zero Allocation: Static memory pools for predictable performance
  • LLM Optimization: Token caching, embedding storage, inference acceleration
  • Production Ready: Comprehensive monitoring, security, and deployment options
  • Seamless Integration: Works perfectly with NenDB, nen-io, and nen-json

Scale to infinity with confidence! ✨

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages