Return-Path: Delivered-To: apmail-jakarta-tomcat-user-archive@www.apache.org Received: (qmail 72200 invoked from network); 29 Sep 2003 13:46:59 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 29 Sep 2003 13:46:59 -0000 Received: (qmail 85584 invoked by uid 500); 29 Sep 2003 13:46:34 -0000 Delivered-To: apmail-jakarta-tomcat-user-archive@jakarta.apache.org Received: (qmail 85471 invoked by uid 500); 29 Sep 2003 13:46:33 -0000 Mailing-List: contact tomcat-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Tomcat Users List" Reply-To: "Tomcat Users List" Delivered-To: mailing list tomcat-user@jakarta.apache.org Received: (qmail 85446 invoked from network); 29 Sep 2003 13:46:32 -0000 Received: from unknown (HELO main.gmane.org) (80.91.224.249) by daedalus.apache.org with SMTP; 29 Sep 2003 13:46:32 -0000 Received: from list by main.gmane.org with local (Exim 3.35 #1 (Debian)) id 1A3yME-0002Pg-00 for ; Mon, 29 Sep 2003 15:46:34 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: tomcat-user@jakarta.apache.org Received: from sea.gmane.org ([80.91.224.252]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1A3yMC-0002PY-00 for ; Mon, 29 Sep 2003 15:46:32 +0200 Received: from news by sea.gmane.org with local (Exim 3.35 #1 (Debian)) id 1A3yMC-0000Lo-00 for ; Mon, 29 Sep 2003 15:46:32 +0200 From: "Christoph Gaffga" Subject: Re: Strange Perfomance decrease with Servlets Date: Mon, 29 Sep 2003 15:33:19 +0200 Organization: Triplemind Internet Services OHG Lines: 187 Message-ID: References: <9C5166762F311146951505C6790A9CF8013DF3A0@US-VS1.corp.mpi.com> X-Complaints-To: usenet@sea.gmane.org X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Sender: news X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N > >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(""); 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("

TestEJBServlet

running...

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

finished!

"); } } --------------------------------------------------------------------- To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: tomcat-user-help@jakarta.apache.org