2 Replies Latest reply on May 23, 2011 10:22 AM by Gabriele Contini

    Cluster SLSB load balancing.

    Gabriele Contini Newbie


      I'm using jboss 6 and I'm trying to load balance remote ejb calls in a cluster. I want that some of the remote calls are routed on nodes other than the current one. (I have a TimerService deployed as a singleton and i want to load balance the batch load).

      I've run into a problem that's documented here:

      http://community.jboss.org/wiki/ClusteringFAQ "Why are calls between clustered session beans not load balanced even though load balancing policy is Round Robin?".

      I don't want to undeploy some of the ejb from one of the containers, so i wrote my own interceptor as described in the wiki.



      package acme;



      import org.jboss.invocation.Invocation;

      import org.jboss.invocation.InvokerInterceptor;



      public class MyInvokerInterceptor extends InvokerInterceptor {




                public boolean hasLocalTarget(final Invocation invocation) {

                          return false;





      Then i tried to configure it in standardjboss.xml. I modified the "clustered-stateless-unified-invoker" replacing:


      <interceptor call-by-value="false">org.jboss.invocation.InvokerInterceptor</interceptor>




      <interceptor call-by-value="false">acme.MyInvokerInterceptor</interceptor>



      and i've configured the correct "invoker-proxy-binding-name" in jboss.xml into my application jar, but yet remote calls always choose the same cluster node where they are generated.



      I tried a completely different way modifying ejb3-interceptors-aop.xml, commenting out:


      <interceptor-ref name="org.jboss.ejb3.remoting.ClusteredIsLocalInterceptor"/>


      at this point remote calls are load balanced and everything seem to work fine (in my sample i use no persistence yet) but i get the following exception:


      12:48:31,049 ERROR [STDERR] java.lang.RuntimeException: cannot import a transaction context when a transaction is already associated with the thread

      12:48:31,050 ERROR [STDERR]           at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:62)

      12:48:31,050 ERROR [STDERR]           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)


      How can i avoid this exception?


        • 1. Cluster SLSB load balancing.
          Wolf-Dieter Fink Master

          AFAIK, you can not have transactions across different server (my experience is from EJB2).

          If you start local without a transaction I suppose it will work.


          The default behaviour is to stay local because of a better performance.

          • 2. Cluster SLSB load balancing.
            Gabriele Contini Newbie

            Thank you, you're right starting without a transaction works fine.

            To summarize all my previous post i can say:

            In order to get the SLSB remote calls load balanced in a cluster you must modify "ejb3-interceptors-aop.xml" under the section "ClusteredStatelessSessionClientInterceptors" commenting out:

            <interceptor-ref name="org.jboss.ejb3.remoting.ClusteredIsLocalInterceptor"/>

            And you must call the remote bean without an active transaction in context.


            The invocation stack can be choosen on a "per session bean"  in jboss.xml:










            This strategy requires a modification to a global configuration file. Is there a way to avoid this and do the full configuration inside my ejb jar?

            Somebody is trying to do this without success http://community.jboss.org/message/536906