0 Replies Latest reply on Nov 27, 2009 6:09 PM by Vinay Pothnis

    Defect: Round Robin Conn. Load Balancing implementation

    Vinay Pothnis Newbie

      I found this when I was debugging through the connection creation code. I have a cluster of 3 HornetQ servers. But the cluster is set up by explicitly specifying the individual connectors.

      I am testing against trunk because this JIRA issue (https://jira.jboss.org/jira/browse/HORNETQ-222) was addressed in the Trunk.

      In the HornetQConnectionFactor.java (line #567) we have:

      // Note that each JMS connection gets it's own copy of the connection factory
      // This means there is one underlying remoting connection per jms connection (if not load balanced)
      ClientSessionFactory factory = sessionFactory.copy();
      


      Everytime, a ConnectionFactory.createConnection() is called, a copy of sessionFactory is made and ClientSessionFactory.initialise() is called. Within this method, a new instance of the loadBalancingPolicy class is instantiated.

      But the RoundRobinConnectionLoadBalancingPolicy.java has the following:

      public int select(final int max)
       {
       if (first)
       {
       //We start on a random one
       pos = random.getRandom().nextInt(max);
      
       first = false;
       }
       else
       {
       pos++;
      
       if (pos >= max)
       {
       pos = 0;
       }
       }
      
       return pos;
       }
      


      The "first" attribtue will always be true everytime because a new instance is created everytime (as stated above).
      So, essentially, this policy becomes "Random" rather than "RoundRobin".

      Please confirm.

      Thanks
      Vinay