10 Replies Latest reply on Oct 28, 2014 1:08 PM by wdfink

    Stateless EJB Method Invocation delay

    dnovo

      Hi,

       

      On my migration from jboss as6.1 to wildfly 8.1, i detect some performance issues.

       

      I have a EJB 3 stateless service like this:

       

      @Stateless

      @Local

      @RolesAllowed("MyRole")

      public class MyService

      {

           public void doStuff()

           {

                System.out.println("STARTED @: " + System.currentTimeMillis());

                //MY CODE...

           }

       

      }

       

      On another class i lookup my service and call doStuff();

       

      MyService service = InitialContext.doLookup(MyServiceJNDI);

      System.out.println("SERVICE CALL @: " + System.currentTimeMillis());

      service.doStuff();

       

      Between service invocation and execution i got 5/6 ms.

       

      I'm using wildfly 8.1 with java 7, standalone configuration.

       

      This delay is causing performance issues to my app.

      Is this a wildfly "bug"? How can i "fix" this?

        • 1. Re: Stateless EJB Method Invocation delay
          wdfink

          I think there is no problem.

          The issue is that AS6 will establich the connection with the lookup as the proxy is downloaded from the server.

          Since AS7 the behaviour has changed, the lookup did not connect to the server this is delayed to the first invoccation.

           

          What if you measure the lookup + the invocation, after the first invocation it should be similar duration

          • 2. Re: Stateless EJB Method Invocation delay
            dnovo

            Hi,

             

            As you suggested i measure de times with lookup plus execution time.

             

            In JBoss AS6.1 / Java 6 i use EJB 2

             

            EJB2 Time with lookup + execution: 4

            EJB2 Time with lookup + execution: 3

            EJB2 Time with lookup + execution: 3

            EJB2 Time with lookup + execution: 3

            EJB2 Time with lookup + execution: 2

            EJB2 Time with lookup + execution: 3


            CODE:

            long start = System.currentTimeMillis();

            MyServiceHome myServiceHome = (MyServiceHome)ServiceLocator.getInstance().getEJBHome(MyServiceHomeJNDI);

            MyService  myService = myServiceHome.create();

            myService.doStuff();

            System.out.println("EJB2 Time with lookup + execution: " + (System.currentTimeMillis() - start));

             

            In Wildfly 8.1 / Java 7...same code

             

            EJB2 Time with lookup + execution: 16

            EJB2 Time with lookup + execution: 14

            EJB2 Time with lookup + execution: 15

            EJB2 Time with lookup + execution: 12

            EJB2 Time with lookup + execution: 13

             

            Then i migrate my service to EJB3 as in initial post

             

            EJB3 Time with lookup + execution: 7

            EJB3 Time with lookup + execution: 8

            EJB3 Time with lookup + execution: 7

            EJB3 Time with lookup + execution: 6

            EJB3 Time with lookup + execution: 8

             

            It's faster than ejb2 ( in wildfly ) but it takes twice the time of AS6.1.

             

            Is this a wildfly configuration issue or a bug/performance issue?

            • 3. Re: Stateless EJB Method Invocation delay
              wdfink

              How your ServiceLocator and client configuration look like?

              • 4. Re: Stateless EJB Method Invocation delay
                dnovo

                Hi,

                 

                All my client's are local, i have no configuration. With ejb3 i'm using static method doLookup from InitalContext.

                 

                InitialContext.doLookup(MyServiceJNDI);



                 


                • 5. Re: Stateless EJB Method Invocation delay
                  wdfink

                  I'm a bit confused as you talk about EJB2 and EJB3, so I'm not sure what you are using.

                  If you use a 'client' inside of an server application I would prefer injection with @EJB to do the work and avoid boilderplate code.

                  This should use the optimal way to establish the connections

                  • 6. Re: Stateless EJB Method Invocation delay
                    dnovo

                    Sorry for the confusion.

                     

                    Let me try to explain:

                    I have a legacy app running on JBoss AS6.1 with jee 6. This app has several ejb 2 modules.

                    We are currently migrating to Wildfly 8.1 with jee7 just changing the necessary code in order to deploy ( JNDI, jboss-ejb.xml, ....)

                    During the first tests we detected some performance issues. For instance, a process that took 1 minute, now takes around 3 minutes to complete.

                     

                    After some debugging we realized that most of the time is spent between lookup and method invocation (prior to the business logic).

                    We thought that the problem was the ejb2, and we changed some services to ejb3. It was as little better (and I mean only a little), and as you can see from the previous post, the ejb3 execution still takes 2 times longer than the original ejb2 code (in AS6).

                     

                    Unfortunately, we cannot inject the ejb3 services using the @EJB, and our only option is using bean lookup with the correct jndi.

                     

                    Currently, my jboss-ejb3.xml look like this:

                     

                    <?xml version="1.0" encoding="UTF-8"?>

                    <jboss:jboss

                            xmlns="http://java.sun.com/xml/ns/javaee"

                            xmlns:jboss="http://www.jboss.com/xml/ns/javaee"

                            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                            xmlns:s="urn:security:1.1"

                            version="3.1" impl-version="2.0">

                     

                        <assembly-descriptor>

                            <s:security>

                                <!-- Even wildcard * is supported -->

                                <ejb-name>*</ejb-name>

                                <!-- Name of the security domain which is configured in the EJB3 subsystem -->

                                <s:security-domain>MyDomain</s:security-domain>

                            </s:security>

                        </assembly-descriptor>

                    </jboss:jboss>

                     

                    Any thoughts, hint or tips on how to decrease this time, would be greatly appreciated!

                    Thank you once again for your help!

                    • 7. Re: Stateless EJB Method Invocation delay
                      wdfink

                      Is this a invocation to an EJB within the same server or remote?

                      Do you see that the time is spend between the last log message from teh invoker and the first from teh receiver bean?

                      • 8. Re: Stateless EJB Method Invocation delay
                        dnovo

                        Hi,

                         

                        The invocation is within the same server.

                         

                        I'm not sure i understood your second question.

                         

                        As you can see on the first post of this thread, between ejb method invocation and method start takes too long...5/6 ms. Even if i measure the time with lookups it takes a lot more than jboss as6.

                        • 9. Re: Stateless EJB Method Invocation delay
                          lafr

                          The improved time might be caused by the fact, that WildFly does not pool SLSB's. Don't know how it was with JBoss AS 6.1.

                          But now SLSB's instances are always created and destroyed.

                          See also http://wildfly-development.1055759.n5.nabble.com/Pooling-EJB-Session-Beans-per-default-td5714566.html.

                          • 10. Re: Stateless EJB Method Invocation delay
                            wdfink

                            You might add the SLSB instance pool to the configuration of the ejb3 subsystem. If you use the CLI it will be easy if you use tab completition.