Github user necouchman commented on a diff in the pull request:

    
https://github.com/apache/incubator-guacamole-client/pull/161#discussion_r119971562
  
    --- Diff: 
extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java
 ---
    @@ -180,8 +188,15 @@ protected ModeledConnection 
acquire(RemoteAuthenticatedUser user,
                 @Override
                 public int compare(ModeledConnection a, ModeledConnection b) {
     
    -                return getActiveConnections(a).size()
    -                     - getActiveConnections(b).size();
    +                // Get connection weight for the two systems being 
compared.                
    +                int weightA = a.getConnectionWeight().intValue();
    +                int weightB = b.getConnectionWeight().intValue();
    +
    +                // Get current active connections, add 1 to both to avoid 
calculations with 0.
    --- End diff --
    
    It seems like this might actually matter for number of connections.  If you 
have connections A, B, and C, with weights 1, 2, and 3 respectively, and no 
connections to any of them, then, ideally, with a weighted algorithm, you'd 
like C to get the first connection because it has the larger weight.  If the 
number of active connections is 0, then the net weight for a host evaluates to 
zero, which messes up this balancing case a little bit.  It may not be the end 
of the world, but it's less than ideal.  By adding one to both of the 
connections being compared, connections with 0 active connections will be 
"correctly" (or, maybe, more ideally?) evaluated for their weight.
    
    The reason that I removed the check for the weight calculation is that 
items with a weight < 1 are removed, anyway, so the sorting for those items 
doesn't matter, at all.  This isn't true for active connections, obviously, so 
it seems like adding one here makes the weight behave as expected when a 
connection has zero active connections.
    
    Or am I worrying too much about a corner case?


---
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