pub fn calculate_optimal_batch_size() -> usizeExpand description
Calculate optimal batch size based on available system memory
Automatically determines an appropriate batch size for the sync daemon based on the amount of available system memory. This prevents OOM errors on memory-constrained instances while maximizing throughput on larger ones.
§Memory Model
The calculation assumes:
- Each row consumes approximately 2KB in memory (conservative estimate for wide tables)
- We should use at most 25% of available memory for batch processing
- Minimum batch size: 1,000 rows (for very constrained systems)
- Maximum batch size: 50,000 rows (diminishing returns beyond this)
§Returns
Optimal batch size in number of rows, or default of 10,000 if detection fails.
§Examples
use database_replicator::utils::calculate_optimal_batch_size;
let batch_size = calculate_optimal_batch_size();
println!("Using batch size: {}", batch_size);
// On t3.nano (512MB): ~1,000-2,000
// On t3.small (2GB): ~10,000
// On t3.large (8GB): ~50,000 (capped)