tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Christoph Gaffga" <cgaf...@triplemind.com>
Subject Re: Strange Perfomance decrease with Servlets
Date Mon, 29 Sep 2003 13:33:19 GMT
> >I call the main-method from my test class the command line.
> >- The method does lookup an Entity EJB on JBoss server.
> >- Get a Property from the Bean
> >- Serialize the Bean using Betwixt
> >
> >Then I tested the same by calling the same method from an servlet, it
> >slowes down dramatically:
> >
> >          |Command Line | from Servlet
> >----------+-------------+-------------
> >Lookup    |  144 ms     |  2490 ms
> >Getter    |   17 ms     |  2843 ms
> >Serialize |  708 ms     | 64147 ms
> >
> >Has anybody an idea what causes this slowdown, or anybody
> >seen something similar before?
> >Any help would be apriciated.
>
> Strange.  How is your test set up, that is:
> - Is the command-line class on the same server as JBoss?

yes, it's on the same server, but in another jvm, the tomcat-instance also.

> - Is the test class in the same jar as the bean class?

i didn't package the jar. just plain .class-files-directory in the
classpath.

> - Are you sure the Getter isn't doing another lookup?

I'm sure, the getter getId() only return an Integer. Should be fast.

> - I have no clue why serialization is two orders of magnitude slower...
:(

I was first thinking it's a problem with all the jars in the classpath and
reflection, but it I run my commandline test with the same classpath and the
same jvm options like tomcat, it slows down only about 5 to 10%

>
> Post the tested class and the test class.

The Source is below:

The TestClient-Class (I call this from command line or from the servlet)
------------------------------------------------------------------------
package com.triplemind.samples;

import java.io.IOException;
import java.io.StringWriter;
import java.lang.reflect.Proxy;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;

import org.apache.commons.betwixt.XMLIntrospector;
import org.apache.commons.betwixt.io.BeanWriter;
import org.apache.commons.betwixt.strategy.ClassNormalizer;
import org.apache.commons.logging.impl.SimpleLog;
import com.triplemind.accommodation.AccommodationRemote;
import com.triplemind.accommodation.AccommodationRemoteHome;

public class TestClient {
  public static void main(String[] args) throws IOException {
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY,
            "org.jnp.interfaces.NamingContextFactory");
    env.put(Context.PROVIDER_URL, "localhost:1099");
    env.put("java.naming.factory.url.pkgs",
            "org.jboss.naming:org.jnp.interfaces");
    try {

      Context ctx = new InitialContext(env);
      Object obj = ctx.lookup("Accommodation");

      System.out.print("Lookuped: ");
      System.out.println(obj);

      AccommodationRemoteHome home = (AccommodationRemoteHome)
javax.rmi.PortableRemoteObject.
          narrow(
          obj, AccommodationRemoteHome.class);

      long time = System.currentTimeMillis();

      AccommodationRemote acco = home.findByPrimaryKey(new Integer(2157));

      long time2 = System.currentTimeMillis();

      System.out.println(acco.getId());

      long time3 = System.currentTimeMillis();

      System.out.println(acco.getLocation());
      System.out.println("IsProxy: " +

Boolean.toString(java.lang.reflect.Proxy.isProxyClass(acco.getClass())));

      System.out.println(acco.getClass().toString() + " implements:");
      Class[] interf = acco.getClass().getInterfaces();
      for (int i = 0; i < interf.length; i++) {
        System.out.println(" - " + interf[i].toString());
      }

      SimpleLog log = new SimpleLog("Logger");
      log.setLevel(log.LOG_LEVEL_ALL);

      StringWriter outputWriter = new StringWriter();
      BeanWriter beanWriter = new BeanWriter(outputWriter);

      XMLIntrospector ispec = beanWriter.getXMLIntrospector();

      ispec.setAttributesForPrimitives(false);
      ispec.setLog(log);
      ispec.setClassNormalizer(new ClassNormalizer() {
        public Class normalize(Class clazz) {
          if (Proxy.isProxyClass(clazz) && clazz.getInterfaces().length > 0)
{
            return clazz.getInterfaces()[0];
          }
          return clazz;
        }
      });

      beanWriter.getBindingConfiguration().setMapIDs(true);
      beanWriter.enablePrettyPrint();
      beanWriter.writeXmlDeclaration("<?xml version='1.0' ?>");

      System.out.println("write Bean...");
      beanWriter.write(acco);

      System.out.println(outputWriter.toString());

      System.out.println("Duration 1st EJB: " + Long.toString(time2 - time)
+ "ms");
      System.out.println("Duration 1st getId: " + Long.toString(time3 -
time2) + "ms");
      System.out.println("Duration 1st XML: " +
Long.toString(System.currentTimeMillis() - time3) +
                         "ms");

      log.setLevel(log.LOG_LEVEL_OFF);
      time = System.currentTimeMillis();
      for (int i = 0; i < 1000; i++) {
        beanWriter.write(acco);
      }
      System.out.println("Duration: " +
Long.toString(System.currentTimeMillis() - time) + "us");

    } catch (Exception e) {
      e.printStackTrace();
      System.out.println("Exception: " + e.getMessage());
    }
  }
}


Test Servlet, this is very slow
-----------------------------------------------------------------
package com.triplemind.samples;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletOutputStream;

public class TestEJBServlet extends HttpServlet {

  protected void service(HttpServletRequest request, HttpServletResponse
response) throws
      ServletException, IOException {

    ServletOutputStream out = response.getOutputStream();
    out.println("<html><body><h1>TestEJBServlet</h1><p>running...</p>");

    TestClient.main(new String[] {});

    out.println("<p>finished!</p></body></html>");
  }

}






Mime
View raw message