RpcNet
A low latency RPC library for cluster building with full QUIC+TLS and SWIM support
Getting Started • Documentation • User Guide • Examples • Benchmarks
Features
Core Features
- 🔒 TLS Security: Built-in TLS 1.3 encryption and authentication
- ⚡ Async/Await: Full async support with optimized Tokio runtime
- 📦 Binary Serialization: Efficient data serialization with bincode
- 🛡️ Type Safety: Strongly typed RPC calls with compile-time guarantees
- 🔧 Code Generation: Generate type-safe client and server code from service definitions
- ⏱️ Timeout Handling: Configurable request timeouts with automatic cleanup
- 🔍 Error Handling: Comprehensive error types for robust applications
- 📊 Production Ready: Battle-tested with extensive test coverage
Cluster & Distributed Systems
- 🌐 Cluster Management: Built-in distributed cluster support with automatic node discovery
- 🔄 Load Balancing: Multiple strategies (Round Robin, Random, Least Connections)
- 💓 Health Checking: Phi Accrual failure detection for accurate health monitoring
- 🗣️ Gossip Protocol: SWIM-based gossip for efficient cluster communication
- 🏷️ Tag-Based Routing: Route requests to workers by tags (role, zone, GPU/CPU, etc.)
- 📡 Event System: Real-time cluster events (NodeJoined, NodeLeft, NodeFailed)
- 🔁 Auto-Discovery: Workers automatically discovered via gossip protocol
- 🛡️ Partition Detection: Automatic detection and handling of network partitions
🚀 Performance
- Exceptional throughput with full encryption (exceeds HTTP/1.1 performance!)
- Modern transport with connection multiplexing and 0-RTT resumption
- Custom QUIC limits, efficient buffer management, and minimal allocations
- Handle 10k+ simultaneous streams per connection
- Under 100µs RTT over TLS overhead
Installation
Add RpcNet to Your Project
Add rpcnet to your Cargo.toml:
[]
= "0.1.0"
= { = "1.0", = ["full"] }
= { = "1.0", = ["derive"] }
= "0.1"
# Optional: For code generation in build.rs
[]
= { = "0.1.0", = ["codegen"] }
Installing the CLI Tool
The rpcnet-gen CLI tool generates type-safe client and server code from service definitions. The CLI is included by default when you install rpcnet.
# Install from crates.io (includes rpcnet-gen CLI)
# Or install from source
Verify installation:
Code Generation
RpcNet includes a code generator that creates type-safe client and server code from service definitions.
1. Create a Service Definition
Create a .rpc.rs file using standard Rust syntax:
// calculator.rpc.rs
use ;
2. Generate Code
Use the CLI tool to generate client and server code:
# Generate code from service definition
# Multiple files
3. Use Generated Code
Server Implementation
use RpcConfig;
use ;
use ;
;
async
Client Usage
use RpcConfig;
use ;
async
4. Build Integration
Add to your build.rs:
Quick Start
Prerequisites
- Add to your
Cargo.toml:
[]
= "0.1.0"
= { = "1.0", = ["full"] }
= { = "1.0", = ["derive"] }
- Generate TLS certificates (for development):
# Create a certs directory
&&
# Generate a self-signed certificate for development
Server Example
use ;
async
Client Example
use ;
async
Testing
RpcNet maintains 65%+ test coverage with comprehensive unit tests, integration tests, and examples:
# Run all tests
# Generate coverage report
# Check coverage meets 65% threshold
# Analyze coverage gaps
# Test examples
Coverage Requirements
- Overall Project: 65% minimum coverage
See docs/COVERAGE.md for detailed coverage information and TESTING.md for testing guidelines.
Benchmarking
RpcNet includes comprehensive benchmarks demonstrating its exceptional performance:
# Run benchmarks (standard)
# Run benchmarks with performance optimizations (jemalloc allocator)
# Specific benchmark scenarios
Examples
Basic Examples (No Setup Required)
Simple examples using the low-level API that work immediately:
# Basic server and client
# Echo server with text/binary handling
Advanced Examples (Code Generation)
Complete, self-contained examples demonstrating code generation:
| Example | Description |
|---|---|
basic_greeting/ |
Simple request/response service |
echo/ |
Binary data and multiple methods |
file_transfer/ |
Chunked operations and stateful services |
calculator/ |
Mathematical operations with error handling |
concurrent_demo/ |
Concurrent operations and shared state |
# Generated code examples (require codegen feature)
Cluster Examples
Production-ready cluster example demonstrating distributed systems:
# Terminal 1 - Start director/coordinator
DIRECTOR_ADDR=127.0.0.1:61000 RUST_LOG=info \
# Terminal 2 - Start worker A
WORKER_LABEL=worker-a WORKER_ADDR=127.0.0.1:62001 \
DIRECTOR_ADDR=127.0.0.1:61000 WORKER_FAILURE_ENABLED=true RUST_LOG=info \
# Terminal 3 - Start worker B
WORKER_LABEL=worker-b WORKER_ADDR=127.0.0.1:62002 \
DIRECTOR_ADDR=127.0.0.1:61000 WORKER_FAILURE_ENABLED=true RUST_LOG=info \
# Terminal 4 - Start client
DIRECTOR_ADDR=127.0.0.1:61000 RUST_LOG=info \
# See examples/cluster/README.md for detailed setup and configuration
Key cluster features demonstrated:
- Automatic worker discovery via gossip protocol
- Load balancing strategies (Round Robin, Random, Least Connections)
- Phi Accrual failure detection with simulated failures
- Tag-based routing and filtering
- Zero-downtime worker failover and recovery
📚 For comprehensive tutorials and documentation, see cargo doc --open
Documentation
📖 Read the User Guide
The comprehensive user guide is available online at jsam.github.io/rpcnet and includes:
- 📚 Complete Tutorial: Step-by-step guide from basics to advanced patterns
- 🔨 Code Generation: Complete guide to the code generation feature
- 🌐 Cluster Management: Distributed systems and load balancing
- 🚀 Performance Guide: Benchmarking and optimization tips
- 💡 Best Practices: Production deployment recommendations
- 📝 Examples: Working code you can copy and adapt
API Documentation
# Open the API reference documentation locally
The API documentation includes:
- 🔧 Full API Reference: Complete documentation of all public APIs
- 🧪 Testing Guide: Comprehensive testing and coverage information
- 📊 Coverage Report: Detailed coverage metrics