Github user mike-jumper commented on a diff in the pull request:

    
https://github.com/apache/incubator-guacamole-client/pull/161#discussion_r119922302
  
    --- Diff: 
extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java
 ---
    @@ -179,9 +187,27 @@ protected ModeledConnection 
acquire(RemoteAuthenticatedUser user,
     
                 @Override
                 public int compare(ModeledConnection a, ModeledConnection b) {
    -
    -                return getActiveConnections(a).size()
    -                     - getActiveConnections(b).size();
    +                
    +                int weightA, weightB;
    +                // Check if weight of a is non-null and retrieve it.
    +                if (a.getConnectionWeight() != null && 
a.getConnectionWeight().intValue() > 0)
    +                    weightA = a.getConnectionWeight().intValue();
    +                // In all other cases assign 1 for sorting.
    +                else
    +                    weightA = 1;
    +
    +                // Check if weight of b is null, assign 1 if it is.
    +                if (b.getConnectionWeight() != null && 
b.getConnectionWeight().intValue() > 0)
    +                    weightB = b.getConnectionWeight().intValue();
    +                // In all other cases assign 1 for sorting.
    +                else
    +                    weightB = 1;
    +
    +                // Get current active connections, add 1 to both to avoid 
calculations with 0.
    +                int connsA = getActiveConnections(a).size() + 1;
    +                int connsB = getActiveConnections(b).size() + 1;
    +
    +                return (connsA * 10000 / weightA) - (connsB * 10000 / 
weightB);
    --- End diff --
    
    > ... the idea is to get the numerator sufficiently high so that an integer 
calculation will actually happen.
    
    Ick. =/
    
    With normal WLC, the idea is that a server with weight N should be 
allocated N times as many connections as a server with weight 1, correct? That 
way weights can be calculated based on the proportion of resources available on 
each server relative to some arbitrary baseline?
    
    I agree that multiplying each of the compared values by a constant will not 
alter the above relationship, but I'm not a fan of the arbitrariness of that 
constant here.
    
    If that constant were instead `weightB * weightA`, this would become:
    
        return (connsA * weightB * weightA / weightA) - (connsB * weightB * 
weightA / weightB);
    
    which clearly reduces to:
    
        return (connsA * weightB) - (connsB * weightA);
    
    which is nice and integery. You won't get the same values, *but* you will 
get the same sign, which is all that matters here.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to