14 Replies Latest reply on Mar 1, 2009 2:16 AM by ron_sigal

    Socket keep alive with client EJB and RMI over HTTP

    slimamar

      As described in this topic :
      http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4148258#4148258
      using version 2.4.0 of Remoting and the parameter 'invokerDestructionDelay', the same socket connection is reused for all client requests to the Server.
      This works fine with the socket transport.

      Now, we want to use the HTTP transport. The parameter 'invokerDestructionDelay' is taken into account and the HTTPClientInvoker is not removed but the socket is closed at each call.

      What's wrong, in the JBoss Remoting Guide i don't see any parameter for HTTP client invoker and by default with HTTP/1.1 the connections are persistent.

      Thanks in advance.

        • 1. Re: Socket keep alive with client EJB and RMI over HTTP
          ron_sigal

          Hmm. I don't really know what's happening. On the client side the HTTP transport uses a java.net.HttpURLConnection, and on the server side it uses a Tomcat Coyote Connector (http://tomcat.apache.org/tomcat-4.1-doc/config/coyote.html), so Remoting doesn't have a lot of control over the use of connections. Note that the keep-alive mechanism is implementation dependent, so there's no guarantee about how long connections will remain open.

          One thing you could try is setting the "timeout" parameter in the EJB3 Connector. E.g.,

           <mbean code="org.jboss.remoting.transport.Connector"
           name="jboss.remoting:type=Connector,name=DefaultEjb3Connector,handler=ejb3">
           <depends>jboss.aop:service=AspectDeployer</depends>
           <attribute name="InvokerLocator">socket://${jboss.bind.address}:3873/?timeout=300000</attribute>
           <attribute name="Configuration">
           <handlers>
           <handler subsystem="AOP">org.jboss.aspects.remoting.AOPRemotingInvocationHandler</handler>
           </handlers>
           </attribute>
           </mbean>
          


          This configuration would set the socket timeout, on both the client and server side, to 5 minutes. Just a thought.

          • 2. Re: Socket keep alive with client EJB and RMI over HTTP
            slimamar

            Hi,

            The 'timeout' parameter works fine with the socket transport as described in your config but not with this config (http transport) :

             <mbean code="org.jboss.remoting.transport.Connector"
             name="jboss.remoting:type=Connector,name=DefaultEjb3Connector,handler=ejb3">
             <attribute name="InvokerLocator">servlet://${jboss.bind.address}:8080/servlet-invoker/ServerInvokerServlet/?timeout=300000</attribute>
             <attribute name="Configuration">
             <handlers>
             <handler subsystem="AOP">
             org.jboss.aspects.remoting.AOPRemotingInvocationHandler
             </handler>
             </handlers>
             </attribute>
             </mbean>
            


            • 3. Re: Socket keep alive with client EJB and RMI over HTTP
              ron_sigal

              In what sense doesn't "timeout" work with the servlet transport? What phenomenon do you see?

              Are you really using 8080 as the EJB3 port? Doesn't that conflict with the tomcat/jbossweb port?

              • 4. Re: Socket keep alive with client EJB and RMI over HTTP
                slimamar

                With the servlet transport, there is no conflict with jbossweb port (8080) because a servlet is used with the connector http.

                With the socket transport, the connections remain open when using the parameters 'invokerDestructionDelay' (client side) and 'timeout' (server side) .

                With the servlet or http transport, the socket connections are immediately closed by the client after each call.

                • 5. Re: Socket keep alive with client EJB and RMI over HTTP
                  ron_sigal

                   

                  "ron.sigal@jboss.com" wrote:

                  Are you really using 8080 as the EJB3 port? Doesn't that conflict with the tomcat/jbossweb port?


                  Let's just forget I said that. http://en.wikipedia.org/wiki/Image:Homer_doh2.png


                  With the servlet or http transport, the socket connections are immediately closed by the client after each call.


                  Ah, so adding "timeout" didn't help. I'm just not sure what's happening. One thing to try would be to turn up logging in tomcat/jbossweb by adding

                   <category name="org.apache">
                   <priority value="DEBUG"/>
                   </category>
                  


                  to ${JBOSS_HOME}/server/${CONFIG}/conf/jboss-log4j.xml.

                  • 6. Re: Socket keep alive with client EJB and RMI over HTTP
                    slimamar

                    I think the problem comes from the client side.

                    We have developped an web application and deploy it with JBoss.
                    For this application, we use the Jakarta common-httpclient to have persistent connection and this works fine.

                    I think the problem comes from the HTTPClientInvoker.

                    Is it possible to use the Jakarta common-httpclient with JBoss remoting.

                    • 7. Re: Socket keep alive with client EJB and RMI over HTTP
                      ron_sigal

                       


                      Is it possible to use the Jakarta common-httpclient with JBoss remoting.


                      Should be.

                      1. Unlike other Remoting transports, which expect to send and receive serialized Remoting objects, the http transport is able to send and receive Strings. So I guess you could use HTTPClient to communicate with org.jboss.remoting.transport.coyote.CoyoteInvoker, which is the server side of the Remoting HTTP transport. Never tried it, though.

                      2. If you just send application strings back and forth, you wouldn't have access to Remoting facilities like connection monitoring. An alternative to using a "raw" HTTPClient would be to override the code in org.jboss.remoting.transport.http.HTTPClientInvoker that uses java.net.HttpURLConnection with code that uses HTTPClient. In effect you would be creating your own transport. For more information about how to do that, see Remoting Guide 2.4.0.GA "Chapter 6. Adding a New Transport" (http://www.jboss.org/jbossremoting/docs/guide/2.4/html/index.html).

                      • 8. Re: Socket keep alive with client EJB and RMI over HTTP
                        ron_sigal

                        I've been doing some experimenting, and I've found that if I run a loop like this:

                        
                         for (int i = 0; i < 100; i++)
                         {
                         Client client = new Client("http://localhost:5555");
                         client.connect();
                         client.invoke("abc");
                         client.disconnect();
                         Thread.sleep(5000);
                         }
                        


                        a new socket is created for each invocation, but if I reduce the delay to 4000 ms, a single socket gets reused. So it seems that Sun's java.net.HttpURLConnection implementation has some built in socket recycling mechanism, which, unfortunately, is inaccessible from the outside. I've tried playing with a ping mechanism to try to keep a single socket alive, but it's not working. Even if it did, there's no guarantee that it would work in another Java implementation.

                        One solution would be to change org.jboss.remoting.transport.http.HTTPClientInvoker to use something other than HttpURLConnection, something like Apache HttpClient. However, the sun is setting on Remoting 2 and rising on Remoting 3, so the time has passed for significant development of Remoting 2. Instead, we'll just make sure the problem does not arise in Remoting 3.

                        • 9. Re: Socket keep alive with client EJB and RMI over HTTP
                          slimamar

                          Using JBoss Remoting 2.4.0 with JBossAS 5.0.0Beta4, the parameter 'invokerDestructionDelay' is taken into account and the socket connection is reused for all client requests.

                          But with JBossAS 5.0.0GA and JBoss Remoting 2.5.0SP2 embedded, the socket connection is closed, apparently by the server, after 60 seconds of inactivity.
                          The value of 'invokerDestructionDelay' is 28800000.

                          • 10. Re: Socket keep alive with client EJB and RMI over HTTP
                            ron_sigal

                             

                            "slimamar" wrote:

                            But with JBossAS 5.0.0GA and JBoss Remoting 2.5.0SP2 embedded, the socket connection is closed, apparently by the server, after 60 seconds of inactivity.


                            Are we talking about the "http" transport or the "socket" transport?

                            • 11. Re: Socket keep alive with client EJB and RMI over HTTP
                              slimamar
                              • 12. Re: Socket keep alive with client EJB and RMI over HTTP
                                ron_sigal

                                Response on thread "Socket keep alive with client EJB", http://www.jboss.com/index.html?module=bb&op=viewtopic&t=134089.

                                • 13. Re: Socket keep alive with client EJB and RMI over HTTP
                                  sukhdesi

                                  Hi,

                                  I am also facing the same kind of issue. I am using jboss 4.2.3. I have developing an jboss web service client. After the web service call is completed underlying TCP connection gets disconnected. I want to keep it forever since server side is being developed in gSOAP/C++ which expects same socket.

                                  Is there any configuration so that we can keep connection alive forever?

                                  Please provide some suggestion.

                                  Regards
                                  Sukhdev

                                  • 14. Re: Socket keep alive with client EJB and RMI over HTTP
                                    ron_sigal

                                    Hi Sukhdev,

                                    I assume you're using the Remoting http transport, in which case you should see my response on this thread from Aug 4, 2008. I'm afraid I don't have a solution at the moment. The http transport hasn't yet been written for Remoting 3, but we'll try to keep this issue in mind.

                                    -Ron