Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Tomcat Vs. Other Java Server Speed Issue  RSS feed

 
Vikas Aggarwal
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!,
In one of a test project we are trying to run Java Servlets/JSPs on Tomcat. The speed is very slow and a 40kb page takes 22.04 seconds to download.
The backends are: Unix, mysql
Is there anything that can be done to improve speed or it is due to the combinations of UNIX, MYSQL and TOMCAT? If any other free container/server is available which can improve speed?
Thanks.
 
Sam Dalton
Author
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might want to try and precomile your JSPs. I suspect that the major speed hit is compiling the JSP the first time...
S
 
Sam Kebab
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vikinsa,
22 seconds is an eternity. Aside from precompiling your jsp/servlet, do check your database driver. In my previous project, i had problems with an open source driver, that made the database query extremely slow -- even more than 22 seconds. After changing drivers, the execution time was a much faster 1.5 seconds.
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To track it down further, you could do something like: Either put that to the log, or System.out or even to the 'out' of the servlet/jsp. And replace "xxxx" with an operation. So you'd have a timing trace on all the operations like:

time after servlet init:
time after parsing request params:
time after obtaining db connection:
time after doing SQL Query:
etc, etc...
 
Vikas Aggarwal
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot you guys have been very helpful. I have taken all of the recommendations from you in account and guess what the main reason was the database problem. The driver was not supporting the connection pooling perfectly. I tuned the pooling to match the driver properties and it is now 5 seconds fatser.
One more quick question for you: How can I come to know that how many connections should be opened for a particular program?
Thanks.
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your connection pool should take care of that for you. You obtain a connection from the pool when you need to do something with a database, and you return it to the pool when you are done. So the pool opens connections transparently to the end user of the pool.

If your pooling mechanism has settings that allow you to set the 'minimum' and 'maximum' open connections, then I think a sizing exercise is the way to go.

Basically load test you application under light, normal and heavy loads. The actual numbers will depend on who is using your system, and for what.

Simply adjust up and down, the pool settings, until you achieve the best performance.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!