{"id":26649825,"url":"https://github.com/nubskr/nubmq","last_synced_at":"2025-03-25T01:02:06.923Z","repository":{"id":262723111,"uuid":"858384155","full_name":"nubskr/nubmq","owner":"nubskr","description":"A high performant key value caching engine engineered from first principles","archived":false,"fork":false,"pushed_at":"2025-03-22T19:36:08.000Z","size":9720,"stargazers_count":272,"open_issues_count":1,"forks_count":15,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-22T20:27:19.849Z","etag":null,"topics":["caching","database","go","golang","nosql"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nubskr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-16T19:55:06.000Z","updated_at":"2025-03-22T19:36:12.000Z","dependencies_parsed_at":null,"dependency_job_id":"8b477804-40ea-49e9-a34c-6e332fb4904c","html_url":"https://github.com/nubskr/nubmq","commit_stats":null,"previous_names":["nubmq/nubmq-engine"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nubskr%2Fnubmq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nubskr%2Fnubmq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nubskr%2Fnubmq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nubskr%2Fnubmq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nubskr","download_url":"https://codeload.github.com/nubskr/nubmq/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245377947,"owners_count":20605378,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["caching","database","go","golang","nosql"],"created_at":"2025-03-25T01:02:05.924Z","updated_at":"2025-03-25T01:02:06.907Z","avatar_url":"https://github.com/nubskr.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# 🚀 nubmq: a high performant key-value cache engine\n\nA blazing-fast KV store written in pure Golang without any dependencies with native pub-sub support, engineered for high-frequency, contention-heavy workloads.\n\n![Architecture](https://raw.githubusercontent.com/nubskr/nubmq/master/assets/nubmq_new_.png)\n\n---\n\n## 🧩 Adaptive Sharding: a self-managing, self-healing system\n\n✨ The system starts from a single bucket and **scales dynamically** in real-time! When keys expire, they immediately stop being served and are removed during the next resizing.\n\n- **Exponential Shard Scaling:** Ensures capacity grows logarithmically, preventing premature resource exhaustion.\n- **Zero Downtime Resizing:** Live shard migration ensures uninterrupted operation. If one store is overloaded, the other takes its place seamlessly!\n- **True Elasticity:** If load contention per shard increases, the engine scales up. If too many keys expire, it scales down.\n- **Two-Engine Model:** Writes shift to a larger engine when contention grows too high while the old engine continues serving reads.\n- **Wait free Reads \u0026 Writes:** Eliminates contention, enabling high-frequency write workloads.\n- **Just Run \u0026 Forget:** Self-managing \u0026 self-healing—no babysitting required!\n\n---\n\n## 🔔 Event-Based Notification Scheduler\n\n💡 **nubmq is polling-free**—notifications are delivered **instantly!** 📨, polling is for suckers\n\n- **Event Scheduler:** No CPU-wasting polling, just pure event-driven updates!\n- **Supported Notifications:**\n  - **Key Expiry:** Get notified the moment a key expires.\n  - **Key Updates:** Real-time updates whenever a key’s value changes.\n- **Subscription Model:**\n  - Clients can **subscribe** to any key channel for updates.\n  - Listen to the `~Ex` channel for key expiries.\n- **Highly Available, Non-Blocking Priority Message Delivery:**\n  - When contention rises, **SET/GET operations** are prioritized over event notifications.\n\n---\n\n## Event-Driven Connection Handling: No Bottlenecks, No Excuses\n\n💡 **Every connection gets its own read and write buffers** to enable non-blocking I/O across concurrent requests! \n\n- **Hierarchical Write Queues:** Critical operations (`SET`, `GET`) always get priority.\n- **Ultra-fast Non-blocking I/O:** Every client interaction is measured in **microseconds**!\n\n---\n\n## Expiry \u0026 Subscription Notifications: Real-time Without Polling! 🚀\n\n🛠️ **nubmq supports native pub-sub** \n\n- **Automatic TTL-based eviction** ensures memory efficiency without manual intervention.\n- **Event subscription notifications** clients can subscribe for events/\n- **No-polling required!** Uses SSE(server side events) for all notifications\n- **Garbage-Free Expiration Cleanup:** Expired keys are soft deleted and permanently removed from engine during upscale/downscale operations.\n\n## 🏗️ Dual-Store Model: Scaling Without Downtime\n\n- 🏛️ **Two-tier storage system:**\n  - Each store consists of multiple shards.\n  - If a store gets congested, **writes shift to a larger store.** \n  - The old store **keeps serving reads** while data migrates.\n  - **Zero downtime, no waiting!** Clients never experience delays.\n  - Once migration is complete, the old store is removed from memory for **garbage collection**.\n\n---\n\n## 🛠 Features\n\n- **Hyperfast SET/GET operations** \n- **Built-in Expiry with TTL** \n- **Real-time Subscription Mechanism** \n- **Pure Golang, No Dependencies** \n- **High-Performance Cache or NoSQL Mode** (Just increase memory limits)\n\n---\n\n## 📝 Command Support \n\n```plaintext\nSET \u003ckey\u003e \u003cvalue\u003e\nSET \u003ckey\u003e \u003cvalue\u003e EX \u003cexpiry_time_in_seconds\u003e\nGET \u003ckey\u003e\nSUBSCRIBE \u003ckey\u003e\n```\n\n---\n\n## Performance Beyond Limits 🏎️\n\nnubmq squeezes every drop of performance from modern CPUs!\n\n- **Parallelized Goroutines:** No single-threaded nonsense—everything runs concurrently.\n- **Atomic Operations:** Ensures rock-solid data integrity.\n- **Benchmark Results:** 900µs write latency, 500µs read latency under extreme load.\n- **Peak Throughput:** 115,809 ops/sec with 100 concurrent clients on an M2 MacBook Air.\n\n---\n\n## 📊 nubmq vs. The Rest\n\n| Feature                | nubmq                 | Redis             | Memcached        | Etcd            |\n|------------------------|----------------------|-------------------|-----------------|----------------|\n| **Architecture**       | Adaptive Sharding   | Single-threaded  | Static Buckets  | Raft Consensus |\n| **Scalability**        | Auto-Scales Up/Down | Vertical Scaling | Horizontal Only | Limited        |\n| **Write Latency**      | **900µs**           | ~1.1ms           | ~1.5ms          | ~3ms           |\n| **Read Latency**       | **500µs**           | ~700µs           | ~1ms            | ~2ms           |\n| **Max Throughput**     | **178,766 ops/sec** | ~85,000 ops/sec  | ~60,000 ops/sec | ~20,000 ops/sec |\n| **Pub/Sub Support**    | Yes, Instantaneous  | Yes, Slow        | No              | No             |\n| **TTL Handling**       | Native, Optimized   | Yes, but Heavy   | No              | No             |\n| **Lock-Free Reads**    | **Yes**             | No               | Yes             | No             |\n| **Memory Efficiency**  | High, Dynamic GC    | Medium           | High            | Low            |\n| **Dependencies**       | **None (Pure Go)**  | Libevent, Lua    | Libevent        | Raft           |\n\n📌 *Figures from testing on M2 Air or from official sources*\n\n---\n\n## 📈 Benchmarks\n\nI recently replaced sync.map for buckets to a custom hashtable implementation and got a ~40 percent performance gain!\n\n![Benchmarks](./assets/new_bench.png)\n\nBenchmarked on a 8 core fanless M2 air (all cores maxed out under load)\n\n- Concurrent Clients: **100**\n- Peak Throughput: **178,766 ops/sec**\n- Average Throughput: **133,333.33 ops/sec**\n- Dataset Size: **1,000,000 unique keys**\n- Total Operations: **20,000,000 requests**\n- Total Time Tracked: **150 seconds**\n\nWould love it if someone can test on a better machine and post the results\n\n---\n\n## How to run\n\nfirst start the server with:\n\n```bash\nmake build\n```\n\nrun the benchmark with:\n\n```bash\nmake test\n```\n\nor start the client with:\n\n```bash\ncd ./client\ngo run main.go\n```\n\nnow just play around with commands like you do in redis-cli\n\n---\n\n## 🔨 WIP (Work in Progress)\n\n- **Parallelized Shard Store resizing:** would make shard store resizing faster\n- **Clustering:** currently only supports single nodes 🤖\n\n---\n\nnubmq is still a work in progress and is in no way perfect,there are still some data races here and there and a few unhandled errors feel free to report bugs and contributions in forms of issues and PRs are welcome\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnubskr%2Fnubmq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnubskr%2Fnubmq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnubskr%2Fnubmq/lists"}