4 Replies Latest reply on Nov 15, 2013 5:29 PM by 1117866v

    Client side load balancing

    1117866v

      I am using jboss 6.0.1 AS, with hornetQ instance 2.2.24. I have a 2 node standalone cluster.

      I have the following hornetQ configuration :


              <outbound-socket-binding name="jboss-node-1-jms">

                  <remote-destination host="jboss-node1" port="5445"/>

              </outbound-socket-binding>

              <outbound-socket-binding name="jboss-node-2-jms">

                  <remote-destination host="jboss-node2" port="5445"/>

              </outbound-socket-binding>


                    <connectors>

                          <netty-connector name="netty" socket-binding="messaging"/>

                          <netty-connector name="netty-throughput" socket-binding="messaging-throughput">

                              <param key="batch-delay" value="50"/>

                          </netty-connector>

                          <netty-connector name="netty-jboss-node-1" socket-binding="jboss-node-1-jms"/>

                          <netty-connector name="netty-jboss-node-2" socket-binding="jboss-node-2-jms"/>

                          <in-vm-connector name="in-vm" server-id="0"/>

                      </connectors>

       


                        <pooled-connection-factory name="NodeXAConnectionFactory">

                              <transaction mode="xa"/>

                              <connectors>

                                  <connector-ref connector-name="netty-jboss-node-1"/>

                                  <connector-ref connector-name="netty-jboss-node-2"/>

                              </connectors>

                              <entries>

                                  <entry name="java:/XANodeRemoteConnectionFactory"/>

                              </entries>

                          </pooled-connection-factory>



      my client code runs inside a stateless session bean is as follow :


      InitialContext context = new InitialContext();

        ConnectionFactory connectionFactory = (ConnectionFactory) context.lookup( "java:/XANodeRemoteConnectionFactory" );

        while (i < 1000) {

        Connection connection = connectionFactory.createConnection( "admin", "123123" );

        QueueSession session = (QueueSession) connection.createSession(true, Session.AUTO_ACKNOWLEDGE);

        Queue queue = session.createQueue(TEST_QUEUE);

        QueueSender sender = session.createSender(queue);

        sender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

        TextMessage jmsMessage = session.createTextMessage("Message number " + i++);

        sender.send(jmsMessage);

       

        if (session != null)

        session.close();

        if (sender != null)

        sender.close();

        }

       

      Help me understand, why is the message distribution not 50% node1 and other 50% node2. I see the jboss-cli by default selects a roundrobin policy for the Pooled-Connection-Factory? What am I missing? or is that sessions dont know about the nodes available?

        • 1. Re: Client side load balancing
          mevans7

          Just a guess here -- try creating and closing your queue outside of your loop.  Perhaps creating a new sender for each message inside the loop resets the algorithm.

          • 2. Re: Client side load balancing
            1117866v

            Hey Mark, I figured the answer, but I didn't post it here. if the connection factory is fetched from within the loop the round robin feature would be evident. Thanks Mark.. Vj

            • 3. Re: Client side load balancing
              vbchin2

              Vijay,

               

              I am running into the same situation but getting hold of the connection factory everytime in the loop didn't help either. Did you ensure that what actually triggered the even message distribution is not server-side load balancing between node1 and node2 since those are clustered (I hope) ? If node1 and node2 are acting in a cluster, then only way of being 100% sure that the client-side load-balancing is working is to separate them from forming the cluster and then running the same test.

               

              Hope that helps! Let me know if you have additional thoughts on this,

              • 4. Re: Client side load balancing
                1117866v

                Hey Bhaskar, Sorry about the above answer, I lied the code base was being executing was different and I wrongly posted it. But below is the code that I am using for distributing messages

                public ConnectionFactory getStandaloneRemoteConnectionFactory() {

                        // Check cached cf

                        if (cf != null) {

                            return cf;

                        }

                 

                            // Create a transport config for each node in the cluster

                            String[] hostnames = hostnamesByCluster.get(cluster);

                            TransportConfiguration[] servers = new TransportConfiguration[hostnames.length];

                            for (int i = 0; i < servers.length; i++) {

                                String host = hostnames[i];

                                Map<String, Object> map = new HashMap<String, Object>();

                                map.put("host", host);

                                map.put("port", "5445");

                 

                                TransportConfiguration server = new TransportConfiguration(NettyConnectorFactory.class.getName(), map);

                                servers[i] = server;

                            }

                            // Initialize a native hornetQ connection factory with knowledge of each node

                            HornetQConnectionFactory connectionFactory

                                    =  HornetQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.XA_CF, servers);

                            cf = (ConnectionFactory)connectionFactory; // Cast it to the JMS interface

                            return cf;

                    }