4 Replies Latest reply on Mar 12, 2008 4:07 PM by Brian Stansberry

    Loadbalancing and clustering JBOSS using Apache Http server

    Yugant Shah Newbie

      Hello,
      I have clustered two instances of JBOSS and I have configured the jboss web deployer for load balancing using apache http server.
      Consider I have 2 instances of Tomcat (embedded in JBOSS) say TOM1 and TOM2.
      Loadbalancer1 is TOM1 and TOM2 is Loadbalancer2 are configured in Apache server.
      A request is processed by TOm1 and it goes down(using Ctrl+C) the request is then load balanced to TOM2.In the mean I start TOM1 again.
      And bring TOM2 down...The request state is transfered to TOM1 and TOm1 restarts the processing of same request.
      The problem is that TOM1 throws an exception

      13:24:40,954 INFO [STDOUT] YUGANT Bean:5
      13:24:41,455 INFO [STDOUT] YUGANT Bean:6
      13:24:41,957 INFO [STDOUT] YUGANT Bean:7
      13:24:42,458 INFO [STDOUT] YUGANT Bean:8
      13:24:42,960 INFO [STDOUT] YUGANT Bean:9
      13:24:43,477 ERROR [ServerThread] Worker thread initialization failure
      java.net.SocketException: Connection reset by peer: socket write error
      at java.net.SocketOutputStream.socketWrite0(Native Method)
      at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
      at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
      at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65
      )
      at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)
      at java.io.ObjectOutputStream$BlockDataOutputStream.flush(ObjectOutputSt
      ream.java:1631)
      at java.io.ObjectOutputStream.flush(ObjectOutputStream.java:666)
      at org.jboss.remoting.serialization.impl.java.JavaSerializationManager.s
      endObjectVersion2_2(JavaSerializationManager.java:121)
      at org.jboss.remoting.serialization.impl.java.JavaSerializationManager.s
      endObject(JavaSerializationManager.java:95)
      at org.jboss.remoting.marshal.serializable.SerializableMarshaller.write(
      SerializableMarshaller.java:120)
      at org.jboss.remoting.transport.socket.ServerThread.versionedWrite(Serve
      rThread.java:806)
      at org.jboss.remoting.transport.socket.ServerThread.processInvocation(Se
      rverThread.java:606)
      at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.j
      ava:373)
      at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.jav
      a:166)
      15:06:03,431 INFO [TreeCache] viewAccepted(): [192.168.0.33:1652|17] [192.168.0
      .33:1652, 192.168.0.50:2949]
      15:06:03,463 INFO [TreeCache] locking the subtree at / to transfer state
      15:06:03,479 INFO [StateTransferGenerator_140] returning the state for tree roo
      ted in /(1024 bytes)
      15:06:07,702 INFO [final16] New cluster view for partition final16 (id: 17, del
      ta: 1) : [192.168.0.33:1199, 192.168.0.50:1199]
      15:06:07,702 INFO [final16] I am (192.168.0.33:1199) received membershipChanged
      event:
      15:06:07,702 INFO [final16] Dead members: 0 ([])
      15:06:07,702 INFO [final16] New Members : 1 ([192.168.0.50:1199])
      15:06:07,702 INFO [final16] All Members : 2 ([192.168.0.33:1199, 192.168.0.50:1
      199])

      And the request is left unprocessed.
      I am not able to resolve this issue.

      Thanks in advance.

      Thanks, Yugant Shah.

        • 1. Re: Loadbalancing and clustering JBOSS using Apache Http ser
          murthy g Newbie


          Hi,
          I am doing a similar test. My problem is that the farm deployment doesn't work. I followed this:

          http://docs.jboss.org/jbossas/jboss4guide/r4/html/cluster.chapt.html

          If you haven't looked at it, please do so.

          Also, if possible, please post the 2 cluster-service.xml files or mail them to murthy64@hotmail.com

          Thanks
          Murthy

          • 2. Re: Loadbalancing and clustering JBOSS using Apache Http ser
            Brian Stansberry Master

            Yugant,

            What is going on when this error occurs? Your discussion of your setup talks about load balancing of Tomcat, but the stack trace is not related to the web tier. It seems to be related to EJBs.

            Please describe all the components of your application and how they interact.

            • 3. Re: Loadbalancing and clustering JBOSS using Apache Http ser
              Yugant Shah Newbie

              Hello,

              I am running the simple ejb3 clustering example.

              Where in I have a jsp that calls the bean.This call is in a for loop with time lag in it.
              The bean return the String message that is printed by the jsp on the console.

              I am attaching the code for HelloWorldBean.java

              package com;
              
              import javax.annotation.PostConstruct;
              import javax.annotation.PreDestroy;
              import javax.ejb.Local;
              import javax.ejb.PostActivate;
              import javax.ejb.PrePassivate;
              import javax.ejb.Remote;
              import javax.ejb.Stateful;
              import javax.ejb.Stateless;
              
              import org.jboss.annotation.ejb.Clustered;
              import org.jboss.annotation.ejb.LocalBinding;
              import org.jboss.annotation.ejb.RemoteBinding;
              
              
              @Stateless
              @Remote(HelloWorldInterface.class)
              @RemoteBinding(jndiBinding="ejb/local/HelloWorldBean")
              @Clustered
              public class HelloWorldBean {
              
               public String getMessage(){
               for(int k=0;k<10;k++) {
               Object a = new Object();
               System.out.println("YUGANT Bean:"+k);
               try {
               Thread.sleep(500);
               } catch (InterruptedException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
               }
               }
               return "Say Hello";
               }
               @PreDestroy
               public void preDestroy(){
               System.out.println("HelloWorldBean:preDestroy:");
               }
               @PostActivate
               public void postActivate(){
               System.out.println("HelloWorldBean:postActivate:");
               }
               @PrePassivate
               public void prePassivate(){
               System.out.println("HelloWorldBean:prePassivate:");
               }
               @PostConstruct
               public void postConstruct(){
               System.out.println("HelloWorldBean:PostConstruct:");
               }
              }
              
              
              

              The code for Business interface class is
              package com;
              
              public interface HelloWorldInterface {
               public String getMessage();
              }
              


              The jsp code is :
              
              <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
               pageEncoding="ISO-8859-1"%>
              <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
              <%@page import="java.util.Properties"%>
              <%@page import="javax.naming.Context"%>
              <%@page import="javax.naming.InitialContext"%>
              <%@page import="com.HelloWorldInterface"%>
              <html>
              <head>
              <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
              <title>Insert title here</title>
              </head>
              <body>
              <%
              
              Context ctx = new InitialContext();
               HelloWorldInterface fcs = (HelloWorldInterface)ctx.lookup("ejb/local/HelloWorldBean");
              int k = 0;
              while(k<10) {
               System.out.println(fcs.getMessage()+":"+k);
               Thread.sleep(500);
               k++;
              }
              %>
              



              Thanks,
              Yugant Shah.

              • 4. Re: Loadbalancing and clustering JBOSS using Apache Http ser
                Brian Stansberry Master

                Are there any "Say Hello:X" messages in the log on either server?

                I suspect that all that's happening here is a JSP running on TOM2 is looping making calls against a HelloWorldBean on TOM2. Then the bean is undeployed, so the calls fail over to TOM1. Bean TOM1 goes into a loop logging the "YUGANT Bean:X" messages, and finally returns. By the time it returns the JSP is undeployed on TOM2. The bean client is gone so you get a socket write error when the bean tries to write its response.