7 Replies Latest reply on May 27, 2013 5:22 AM by long_hdi

    JBoss 6EAP on OpenShift, too many active sessions

    long_hdi

      I am using JSF 2 on JBoss 6 EAP. I made a sample application which used JSF as the View, EJB for logic and JPA for Persistence. The bean in JSF has RequestScoped. EJB is stateless.

      This is index.xhtml:

       

      <?xml version='1.0' encoding='UTF-8' ?>
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml"
        
      xmlns:h="http://java.sun.com/jsf/html"
        
      xmlns:c="http://java.sun.com/jsp/jstl/core">
        
      <h:head>
        
      <title>Long HDi</title>
        
      </h:head>
        
      <h:body>
        
      <c:forEach var="tweet" items="#{tweets.getAll}">
        
      <p>
        #{tweet.content}
      <br />
        
      </p>
        
      </c:forEach>
        
      </h:body>
      </html>

       

      JSF Bean:

       

      @Named("tweets")
      @RequestScoped
      public class Tweets implements Serializable {
        
      @EJB
        
      private TweetServiceLocal tweetService;
        
      private List<Tweet> tweets;

        
      public List<Tweet> getGetAll() {
        
      return tweetService.findAllSortedByTimeDesc();
        
      }
      }

       

      EJB:

       

      @Stateless
      public class TweetService implements TweetServiceLocal {

        
      @PersistenceContext(unitName = "LongHDi-ejbPU")
        
      private EntityManager em;

        
      @Override
        
      public Tweet create(final String content, final Date postTime) throws ContentTooLargeException {
        
      if (content.length() > 480)
        
      throw new ContentTooLargeException("Content must have less than 480 charaters!");
        
      else {
        
      try {
        
      Tweet tweet = new Tweet();
        tweet
      .setContent(content);
        tweet
      .setPostTime(postTime);
        em
      .persist(tweet);
        
      return tweet;
        
      } catch (Exception e) {
        
      return null;
        
      }
        
      }
        
      }

        
      @Override
        
      public java.util.List<Tweet> findAllSortedByTimeDesc() {
        
      return em.createNamedQuery("Tweet.findAllSortedByTimeDesc").getResultList();
        
      }

      }

       

      When I sent a few hundred requests to it, the JBoss 6 server threw this exception:

       

      JBWEB000065: HTTP Status 500 - JBWEB000209: Session creation failed due to too many active sessions

      JBWEB000309
      : type JBWEB000066: Exception report

      JBWEB000068
      : message JBWEB000209: Session creation failed due to too many active sessions

      JBWEB000069
      : description JBWEB000145: The server encountered an internal error that prevented it from fulfilling this request.

      JBWEB000070
      : exception

      javax
      .servlet.ServletException: JBWEB000209: Session creation failed due to too many active sessions
        javax
      .faces.webapp.FacesServlet.service(FacesServlet.java:606)
      JBWEB000071
      : root cause

      java
      .lang.IllegalStateException: JBWEB000209: Session creation failed due to too many active sessions
        org
      .apache.catalina.session.StandardManager.createSession(StandardManager.java:297)
        org
      .apache.catalina.connector.Request.doGetSession(Request.java:2651)
        org
      .apache.catalina.connector.Request.getSession(Request.java:2357)
        org
      .apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:790)
        com
      .sun.faces.context.ExternalContextImpl.getSession(ExternalContextImpl.java:157)
        com
      .sun.faces.application.view.FaceletViewHandlingStrategy.getSession(FaceletViewHandlingStrategy.java:494)
        com
      .sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:400)
        com
      .sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:124)
        javax
      .faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:286)
        com
      .sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
        com
      .sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
        com
      .sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
        javax
      .faces.webapp.FacesServlet.service(FacesServlet.java:594)

       

      My question is: why did the server create so many sessions? I used RequestScope and Stateless bean, how come they end up in sessions? What can I do to overcome this situation? If I use only servlet and JSP, when there are too many requests, the server is slowed down but at least it is not halted like this.

        • 1. Re: JBoss 6EAP on OpenShift, too many active sessions
          sfcoy

          What are you using to send the requests?

           

          If you're using a tool it needs to return the JSESSIONID cookie with every subsequent request.

          • 2. Re: JBoss 6EAP on OpenShift, too many active sessions
            long_hdi

            I  wrote Java code to send requests.

             

            First, I need a Java program to read content from a web page:

            http://stackoverflow.com/questions/5232535/read-data-from-webpage

            With a little modification to the code from the link above, I made a program that reads a page and saves the content to a Java object and then destroys the object immediately. (set it to null to save memory).

             

            Second, use a loop to make a thread pool which contains 200 threads. Each thread will create an instance of the program above and read the index.xhtml (using a while(true) loop, so that it will continue to read forever unless I want to interrupt it). Each thread will sleep for 1 second.

             

            Third, make a servlet to use that loop and a JSP to interact with it.

             

            Finally, sign up for an App Fog account. They will give you 2GB RAM. Now, make 4 Java app, 512MB RAM for each instance. Upload the code there, use the JSP to control them. In fact, I only use 1 instance to attack the JBoss gear. After 30 seconds, the JBoss gear threw that exception and coudn't continue to give responses

             

            By using this simple trick, I can easily simulate a few hundred unique visitors to the website. There will be no cookie, no url encoding in this case.

            • 3. Re: JBoss 6EAP on OpenShift, too many active sessions
              sfcoy

              I think JSF gives you a javax.servlet.http.HttpSession whether you want one or not.

               

              If you add "JSF" into the subject (I think you can edit that) Stan Silvert the JBoss JSF guy may comment as well.

              • 4. Re: JBoss 6EAP on OpenShift, too many active sessions
                long_hdi

                it's a pity, I can't edit the title anymore ( Time's out?) though I did  put a JSF tag in there.

                If you have admin permission, please edit the subject for me.

                 

                Moreover, the RequestScoped object should only last in an http-request. That's the specification. Is this the problem of JBoss JSF implementation?

                • 5. Re: JBoss 6EAP on OpenShift, too many active sessions
                  sfcoy

                  Try adding:

                  {code:xml}<context-param>

                      <param-name>javax.faces.STATE_SAVING_METHOD</param-name>

                      <param-value>client</param-value>

                  </context-param>{code}

                  to your web.xml.

                  • 6. Re: JBoss 6EAP on OpenShift, too many active sessions
                    sfcoy

                    Long Hoang wrote:

                     

                    Is this the problem of JBoss JSF implementation?

                    The JBoss JSF implementation is pretty much the reference implementation (Mojarra).

                    • 7. Re: JBoss 6EAP on OpenShift, too many active sessions
                      long_hdi

                      Try adding:

                      <context-param>
                          <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
                          <param-value>client</param-value>
                      </context-param>

                       

                      to your web.xml.

                       

                      It works great man! Now I don't have to worry about it anymore. Thank you so much! I love youuuuuuuuu!