When working with HAProxy's round-robin load balancing algorithm, you can fine-tune traffic distribution by assigning different weights to backend servers. This is particularly useful when you need to:
- Prioritize newer hardware with more capacity
- Gradually introduce new servers into production
- Handle maintenance windows gracefully
For your specific requirement of 70%/15%/15% distribution across three MySQL servers, here's the modified configuration:
listen MySQL 10.10.10.14:3306
mode tcp
balance roundrobin
option persist
server sql1 10.10.10.4:3306 weight 70
server sql2 10.10.10.5:3306 weight 15
server sql3 10.10.10.6:3306 weight 15
After implementing the weighted configuration, you should:
- Check the runtime weights using the HAProxy stats page or CLI
- Monitor the actual traffic distribution with tools like
show stat
- Verify that the weight adjustments don't exceed server capacities
When implementing weighted round-robin in production:
- Make gradual weight changes (10% increments) when possible
- Consider using
on-marked-down
andon-marked-up
options for failover scenarios - Remember that weights only affect new connections, not existing ones
For more dynamic control, you can adjust weights on the fly using runtime API:
echo "set server MySQL/sql1 weight 80" | socat stdio /var/run/haproxy.sock
echo "set server MySQL/sql2 weight 10" | socat stdio /var/run/haproxy.sock
echo "set server MySQL/sql3 weight 10" | socat stdio /var/run/haproxy.sock
The runtime API allows for zero-downtime adjustments, which is crucial for production environments.
When working with HAProxy's round-robin algorithm, the weight
parameter is exactly what you need to achieve uneven distribution of traffic. This becomes particularly useful when you have servers with different capacities or when implementing canary deployments.
Here's how to implement your desired 70/15/15 distribution:
listen MySQL 10.10.10.14:3306
mode tcp
balance roundrobin
option persist
server sql1 10.10.10.4:3306 weight 70
server sql2 10.10.10.5:3306 weight 15
server sql3 10.10.10.6:3306 weight 15
After implementing weighted round robin, verify the distribution using HAProxy's stats page or by analyzing logs. Important considerations:
- Weights are relative - values could be 140/30/30 for same ratio
- Dynamic weight adjustment is possible via runtime API
- Consider
on-marked-down
and on-marked-up
for failover scenarios
For production changes, I recommend this rollout sequence:
- First add weights to non-production environment
- Test with gradual weight changes (e.g., 40/30/30 → 50/25/25 → 70/15/15)
- Use HAProxy's runtime API for zero-downtime adjustments
For dynamic environments, consider these additional parameters:
server sql1 10.10.10.4:3306 weight 70 check inter 5s rise 2 fall 3
server sql2 10.10.10.5:3306 weight 15 backup
server sql3 10.10.10.6:3306 weight 15 disabled