RE: creating a instance of a servlet: takes too long!!

2001-07-06 Thread Michael Wentzel

 why is that my servlet when the first time is invoked, it 
 takes about 30
 seconds or more to start when the servlets that came in tomcat are
 instantaneous? After the servlet container instantiated and 
 initialized my
 servlet, all the following requests are very fast. Is there 
 any advice for
 what we should do and don't do in init() method? 

Well, one option for a solution is set your servlet to load on startup
and have all your initialization done at startup so that these
elements are already initialized before the first request even comes.

 How can I benchmark the time of instantiation of my servlet 
 and the time of
 my init method?

I would just put in some logging code and find out where exactly
the time is being taken up in your servlet(if indeed this is where
it is actually munching clock cycles).

---
Michael Wentzel
Software Developer
Software As We Think - http://www.aswethink.com



RE: creating a instance of a servlet: takes too long!!

2001-07-06 Thread Randy Layman


Really it depends upon what you are doing in your init method.  I
have several servlets that load almost instantly, but don't do anything in
their constructor or init methods.

The only thing that you should do in your init method is to call
super.init at the beginning.

If you want to move the time it takes to initialize, you could use
the web.xml's load-on-startup tag (see the spec for more details) to load
the servlet at Tomcat startup.

You servlet should stay in memory until its shutdown - Tomcat keeps
a reference to the servlet, thus preventing it from being garbage collected.
The only reason, I believe, that a servlet is unloaded during the middle of
Tomcat execution is a newer version is detected on disk.

Randy

 -Original Message-
 From: pedro salazar [mailto:[EMAIL PROTECTED]]
 Sent: Friday, July 06, 2001 5:02 AM
 To: [EMAIL PROTECTED]
 Subject: creating a instance of a servlet: takes too long!!
 
 
 Greetings,
 
 why is that my servlet when the first time is invoked, it 
 takes about 30
 seconds or more to start when the servlets that came in tomcat are
 instantaneous? After the servlet container instantiated and 
 initialized my
 servlet, all the following requests are very fast. Is there 
 any advice for
 what we should do and don't do in init() method? I just 
 initialize some
 properties and a connection pool
 Well is it possible that my servlet container at any time my 
 may shutdown my
 servlet to release memory, and another time it will be 
 requested to start
 again and take another time too long to start, correct?
 
 How can I benchmark the time of instantiation of my servlet 
 and the time of
 my init method?
 
 System configuration:
 -Tomcat 3.2.1
 -JDK 1.3
 -Linux RedHat 6.2 [kernel 2.2.18]
 -PII400Mhz 256Mbytes
 
 thanks.
 --
 psalazar/
 
 
 



Re: creating a instance of a servlet: takes too long!!

2001-07-06 Thread wire



Friday, July 06, 2001, 5:01:37 AM, [EMAIL PROTECTED] wrote:

ps Greetings,

ps why is that my servlet when the first time is invoked, it takes about 30
ps seconds or more to start when the servlets that came in tomcat are
ps instantaneous? After the servlet container instantiated and initialized my
ps servlet, all the following requests are very fast. Is there any advice for
ps what we should do and don't do in init() method? I just initialize some
ps properties and a connection pool
ps Well is it possible that my servlet container at any time my may shutdown my
ps servlet to release memory, and another time it will be requested to start
ps again and take another time too long to start, correct?

ps How can I benchmark the time of instantiation of my servlet and the time of
ps my init method?

ps System configuration:
ps -Tomcat 3.2.1
ps -JDK 1.3
ps -Linux RedHat 6.2 [kernel 2.2.18]
ps -PII400Mhz 256Mbytes

ps thanks.
ps --
ps psalazar/





Re: creating a instance of a servlet: takes too long!!

2001-07-06 Thread wire

If your servlet has changed and needs to be recompiled, then using
jikes instead of javac will save a lot of time.

Friday, July 06, 2001, 5:01:37 AM, [EMAIL PROTECTED] wrote:

ps Greetings,

ps why is that my servlet when the first time is invoked, it takes about 30
ps seconds or more to start when the servlets that came in tomcat are
ps instantaneous? After the servlet container instantiated and initialized my
ps servlet, all the following requests are very fast. Is there any advice for
ps what we should do and don't do in init() method? I just initialize some
ps properties and a connection pool
ps Well is it possible that my servlet container at any time my may shutdown my
ps servlet to release memory, and another time it will be requested to start
ps again and take another time too long to start, correct?

ps How can I benchmark the time of instantiation of my servlet and the time of
ps my init method?

ps System configuration:
ps -Tomcat 3.2.1
ps -JDK 1.3
ps -Linux RedHat 6.2 [kernel 2.2.18]
ps -PII400Mhz 256Mbytes

ps thanks.
ps --
ps psalazar/





RE: creating a instance of a servlet: takes too long!!

2001-07-06 Thread Frederick Lefebvre

The connection pool could cause your problem.  If it initiates many database
connections, it is normal even if your db server was on the same machine
than your app server, for it to take a few seconds per connection.

Fred

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Friday, July 06, 2001 9:18 AM
To: [EMAIL PROTECTED]
Subject: Re: creating a instance of a servlet: takes too long!!


If your servlet has changed and needs to be recompiled, then using
jikes instead of javac will save a lot of time.

Friday, July 06, 2001, 5:01:37 AM, [EMAIL PROTECTED] wrote:

ps Greetings,

ps why is that my servlet when the first time is invoked, it takes about 30
ps seconds or more to start when the servlets that came in tomcat are
ps instantaneous? After the servlet container instantiated and initialized
my
ps servlet, all the following requests are very fast. Is there any advice
for
ps what we should do and don't do in init() method? I just initialize some
ps properties and a connection pool
ps Well is it possible that my servlet container at any time my may
shutdown my
ps servlet to release memory, and another time it will be requested to
start
ps again and take another time too long to start, correct?

ps How can I benchmark the time of instantiation of my servlet and the time
of
ps my init method?

ps System configuration:
ps -Tomcat 3.2.1
ps -JDK 1.3
ps -Linux RedHat 6.2 [kernel 2.2.18]
ps -PII400Mhz 256Mbytes

ps thanks.
ps --
ps psalazar/




Re: creating a instance of a servlet: takes too long!!

2001-07-06 Thread Bo Xu

pedro salazar wrote:

 Greetings,

 why is that my servlet when the first time is invoked, it takes about 30
 seconds or more to start when the servlets that came in tomcat are
 instantaneous? After the servlet container instantiated and initialized my
 servlet, all the following requests are very fast. Is there any advice for
 what we should do and don't do in init() method? I just initialize some
 properties and a connection pool
 Well is it possible that my servlet container at any time my may shutdown my
 servlet to release memory, and another time it will be requested to start
 again and take another time too long to start, correct?

 How can I benchmark the time of instantiation of my servlet and the time of
 my init method?

 System configuration:
 -Tomcat 3.2.1
 -JDK 1.3
 -Linux RedHat 6.2 [kernel 2.2.18]
 -PII400Mhz 256Mbytes

 thanks.
 --
 psalazar/

Hi :-)  one of the ways is like the following:

in WEB-INF/web.xml, add the following into the servlet-declaration of
MyServlet:
...
load-on-startup1/load-on-startup
...

now MyServlet will be loaded/initialized when TC startup.


Bo
June 06, 2001





Re: creating a instance of a servlet: takes too long!!

2001-07-06 Thread Peter Davison

There's another reason for this and it has to do with the java.security.SecureRandom 
class.
From what I can tell, tomcat uses this class to generate a seed value for the
session ID.  The first request for a SecureRandom value (eg. new 
SecureRandom().nextLong()) can take many, many seconds to complete.  After the
first usage however, it returns immediately.  I'm not sure what goes on when
SecureRandom initializes but that seems to be where the slow down occurs.

As a work around, you could create a low priority thread that instantiates a
SecureRandom calls nextLong() then exits, and have this thread get launched by
the init() method of a servlet that gets preloaded.  This solution worked for me.

Regards,
Pete.

Thus spake pedro salazar [EMAIL PROTECTED] on Fri, 6 Jul 2001 10:01:37 
+0100:

PS Greetings,
PS 
PS why is that my servlet when the first time is invoked, it takes about 30
PS seconds or more to start when the servlets that came in tomcat are
PS instantaneous? After the servlet container instantiated and initialized my
PS servlet, all the following requests are very fast. Is there any advice for
PS what we should do and don't do in init() method? I just initialize some
PS properties and a connection pool
PS Well is it possible that my servlet container at any time my may shutdown my
PS servlet to release memory, and another time it will be requested to start
PS again and take another time too long to start, correct?
PS 
PS How can I benchmark the time of instantiation of my servlet and the time of
PS my init method?
PS 
PS System configuration:
PS -Tomcat 3.2.1
PS -JDK 1.3
PS -Linux RedHat 6.2 [kernel 2.2.18]
PS -PII400Mhz 256Mbytes
PS 
PS thanks.
PS --
PS psalazar/
PS 
PS 



Re: creating a instance of a servlet: takes too long!!

2001-07-06 Thread Bo Xu

Bo Xu wrote:

 pedro salazar wrote:

  Greetings,
 
  why is that my servlet when the first time is invoked, it takes about 30
  seconds or more to start when the servlets that came in tomcat are
  instantaneous? After the servlet container instantiated and initialized my
  servlet, all the following requests are very fast. Is there any advice for
  what we should do and don't do in init() method? I just initialize some
  properties and a connection pool
  Well is it possible that my servlet container at any time my may shutdown my
  servlet to release memory, and another time it will be requested to start
  again and take another time too long to start, correct?
 
  How can I benchmark the time of instantiation of my servlet and the time of
  my init method?
 
  System configuration:
  -Tomcat 3.2.1
  -JDK 1.3
  -Linux RedHat 6.2 [kernel 2.2.18]
  -PII400Mhz 256Mbytes
 
  thanks.
  --
  psalazar/

 Hi :-)  one of the ways is like the following:

 in WEB-INF/web.xml, add the following into the servlet-declaration of
 MyServlet:
 ...
 load-on-startup1/load-on-startup
 ...

 now MyServlet will be loaded/initialized when TC startup.

 Bo
 June 06, 2001

Hi :-)  I forgot the following:
with TC4.0-b5,  when load-on-startup1/load-on-startup, I remember:
- MyServlet is loaded, i.e.: One Class object of MyServlet is made
- One instance of MyServlet is made, this instance is for that sevlet-declaration
   which you set load-on-startup1/load-on-startup for
- init(...) method of this instance is invoked, then, for example, your
DBconnectionPool
   is initialized

  But:  you must use That servlet-name/servlet-mapping to invoke MyServlet,
otherwise,
  another instance of MyServlet will be made, and its init(...) will Still be
invoked,
  i.e.: the first time will Still be slow.

and it is possible that container will invoke int(...)/destroy() more than one
time.


Bo
July 06, 2001






RE: creating a instance of a servlet: takes too long!!

2001-07-06 Thread William Kaufman

Note that a good deal of this time might be spent in
HttpServletRequest.getSession(): the 3.2.1 implementation is much slower
than the 3.2.2 version.  You might want to time your calls and, if that's
where the slow-down is, upgrade to 3.2.2.

-- Bill K. 

 -Original Message-
 From: pedro salazar [mailto:[EMAIL PROTECTED]]
 Sent: Friday, July 06, 2001 2:02 AM
 To: [EMAIL PROTECTED]
 Subject: creating a instance of a servlet: takes too long!!
 
 
 Greetings,
 
 why is that my servlet when the first time is invoked, it 
 takes about 30
 seconds or more to start when the servlets that came in tomcat are
 instantaneous? After the servlet container instantiated and 
 initialized my
 servlet, all the following requests are very fast. Is there 
 any advice for
 what we should do and don't do in init() method? I just 
 initialize some
 properties and a connection pool
 Well is it possible that my servlet container at any time my 
 may shutdown my
 servlet to release memory, and another time it will be 
 requested to start
 again and take another time too long to start, correct?
 
 How can I benchmark the time of instantiation of my servlet 
 and the time of
 my init method?
 
 System configuration:
 -Tomcat 3.2.1
 -JDK 1.3
 -Linux RedHat 6.2 [kernel 2.2.18]
 -PII400Mhz 256Mbytes
 
 thanks.
 --
 psalazar/