A lightweight C++/gRPC demo that implements a peer-to-peer, decentralized load-balancing and failover algorithm. Each node periodically heartbeats its own “score” (40% CPU, 30% queue depth, 20% memory‐free, 10% uptime plus jitter) to its neighbors. Incoming tasks are routed to the highest-scoring alive node; on failure, they automatically retry down the score list.
- Weighted scoring based on CPU load, queue length, memory usage, and uptime.
- Heartbeat gossip: each node learns peer scores (and -hops) up to configurable depth.
- Fault tolerance: tasks forward to the next best node if the best one fails, with client and server retry logic.
- Metrics & logs: per-node JSONL metrics, detailed event logs.
- C++17 compiler
- gRPC & Protobuf (v1.35+ recommended)
- CMake (v3.12+)
- Unix-like OS (Linux, macOS)
chmod +x start.sh
./start.sh
mkdir -p build && cd build
cmake ..
make -jStart servers like this:
In build folder run
./server <address of your device>:<port number> <address of your neighbour>:<port number> ...Start client like this:
./client <TASK_ID> "<PAYLOAD>" <REPLY_ADDR> <SERVER1> [<SERVER2> ...]- Score weights: Adjust the constants in
Server::computeScore(). - Max gossip hops: Currently hard-coded to 3, can be made configurable.
- Heartbeat interval & timeout: Edit
heartbeatLoop()and gRPC deadlines inserver.cpp.
- Event logs: JSON lines of named events for debugging (
logs/*.log). - Metrics: JSON lines recording CPU%, memory%, uptime, and score per second (
logs/*.metrics.jsonl).