# Raft Performance Tuning Optimizing Raft for high-throughput workloads. ## Batch Processing Batch multiple client requests into a single AppendEntries RPC: ```go // Example: batch size of 100 entries batchSize := 100 for i := 0; i < len(requests); i += batchSize { end := min(i+batchSize, len(requests)) batch := requests[i:end] leader.AppendEntries(batch) } ``` ## Pipeline Optimization Allow the leader to pipeline log entries without waiting for each Ack: - Set `max_inflight_entries` to 100-1000 - Use a sliding window for acknowledgments - Retry only unacknowledged entries ## Read Index Optimization For read-heavy workloads, use **read index** instead of log replication: 1. Client sends read request to leader 2. Leader commits a heartbeat (no-op) entry 3. Once committed, leader serves read from state machine 4. Followers can serve stale reads directly ## Benchmarks Typical throughput on a 5-node cluster: | Workload | Throughput | Latency (p99) | |----------|-----------|---------------| | Writes only | 50K ops/sec | 5ms | | Mixed (80/20) | 100K ops/sec | 3ms | | Reads only | 500K ops/sec | 0.5ms |