User:Tim Starling (WMF)/LoadBalancer connection metric
Take the adjusted connection count which is the number of open connections plus the number of connection failures over the last 10 seconds.
Load weights which satisfy
The discrepancy between the desired connection count and the actual connection count is
where
A positive number indicates that the server has too many connections. We could normalize by the total connection count:
But that would be noisy when the number of connections is small. We could simply scale it:
That's defensible and easy to understand. Maybe it would get noisy with high traffic. We could combine the two:
or if you like, equivalently
where q, r, s and E are tunable constants.
Obviously you then have to clamp it so that , and then scale it so that the weights add up to 1 again.
With the two tunable constants S and E can be thought of as connection counts. S is the connection count discrepancy which causes the load to be increased or decreased by 100% under low-traffic conditions. E is the total connection count at which the adjustment will be scaled down by half.