GUACAMOLE-102: Correction to WLC algorithm to try to keep ratio no higher than configure weights.

This commit is contained in:
Nick Couchman
2017-06-05 21:34:50 -04:00
parent 25493a8355
commit 874b29bae3

View File

@@ -187,8 +187,24 @@ public class RestrictedGuacamoleTunnelService
@Override
public int compare(ModeledConnection a, ModeledConnection b) {
return ((getActiveConnections(a).size() + 1) * b.getConnectionWeight() -
(getActiveConnections(b).size() + 1) * a.getConnectionWeight());
// Active connections
int Ca = getActiveConnections(a).size();
int Cb = getActiveConnections(b).size();
// Assigned weight
int Wa = a.getConnectionWeight();
int Wb = b.getConnectionWeight();
// Net weight of connections
int NWa = Ca * Wb;
int NWb = Cb * Wa;
// If net weights are equal, return difference in weight
if (NWa == NWb)
return (Wa - Wb);
// Return different in net weights
return (NWa - NWb);
}