You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by keglius <eg...@satnet.lt> on 2007/10/04 18:40:25 UTC

How to increase Tomcat webserver speed?

Hello!

I have a server running Apache Tomcat 5.5 with my Java application. This
Java application uses MySQL 4.1.x and is very server resource intensive. The
application makes a lot of calls to database to gather various information
which is used for reports. My server is AMD 3200+ with 2GBs of RAM and 80gb
hdd. 
Tomcat has 800MB of RAM allocated for it. Currently the whole server has
1.5GB of RAM used, so around 700-800MB is used by the system. The machine
runs Redhat EL4 and Plesk.

I would like to ask you, guys, how can I increase the speed of my Tomcat
webserver, so the application would work faster?

Currently I ran a stress test with 10 users browsing through my application
pages (members area) and I have noticed that it takes an average 5-10
seconds to load the page. I need to increase the site loading speed much
more, so the page loading would be much faster. The server load during the
test was around 2.5% of CPU. System use 1.5 of RAM constantly (800MBs is
allocated for Tomcat).

Do you have any recommendations, anything? Should I add additional RAM?
Should I upgrade to faster CPU? Do you have any recommendations on how could
I optimize the server's software so it would work faster.
All thoughts, advice and everything is welcome.

Thanks!
Keglius
-- 
View this message in context: http://www.nabble.com/How-to-increase-Tomcat-webserver-speed--tf4569998.html#a13043983
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: How to increase Tomcat webserver speed?

Posted by Peter Crowther <Pe...@melandra.com>.
> From: David Delbecq [mailto:delbd+jakarta@oma.be] 
> Since you say CPU usage on your machine is around 5% during 
> those tests, 
> and your database is on same machine as tomcat server,  i doubt the 
> bottleneck really is on database.

The OP never reported on disk I/O - this is often the killer on database
speed, and "80g HDD" to me suggests there's a single, fairly
slow-spinning drive in the box.

> The first ting i'll suggeste is to 
> take all queries run by your application, make an sql script of them, 
> and run this script using a mysql client. If the script 
> returns in less 
> than a second, it's your application the bottleneck at some 
> point. If it 
> takes 10 seconds, improve your database designs, add indexes, reduce 
> queries.

Agree.  Also check the disk I/O load - I didn't see which operating
system the OP is running, but check Physical Disk / Average Disk Queue
Length on Windows (in the Performance tool) or use "vmstat" on most
UNIXes to get a rough-and-ready feel for the disk traffic.

I'm not saying it *is* the problem, but I've seen far too many systems
where disk ends up being the bottleneck!  See "Amdahl's Rule of Thumb"
near the bottom of http://en.wikipedia.org/wiki/Amdahl's_law - a
balanced system needs 1 byte of RAM and 1 bit per second of I/O for each
instruction/second the CPU can run.  These days, the CPUs run 10^9
instructions per second, we have 10^9 bytes of RAM in a system, but most
physical disks peak at around 10^8 bits/s of I/O, or under 10^7 if
they're subject to heavy random access (say by a database).  It's not
enough!

		- Peter

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How to increase Tomcat webserver speed?

Posted by David Delbecq <de...@oma.be>.
Since you say CPU usage on your machine is around 5% during those tests, 
and your database is on same machine as tomcat server,  i doubt the 
bottleneck really is on database. The first ting i'll suggeste is to 
take all queries run by your application, make an sql script of them, 
and run this script using a mysql client. If the script returns in less 
than a second, it's your application the bottleneck at some point. If it 
takes 10 seconds, improve your database designs, add indexes, reduce 
queries. Check the database type (myisam, innodb?) If database is used 
at same time for writing purpose, check it's not your query that has to 
constantly wait for other to commit, due to isolation level being to 
strict. Check you are using the same connection during all you report 
operation, instead of creating a new one for each information bits. 
Creating a new connection to a db has an overhead in time. Check you use 
127.0.0.1 as ip for localhost database and not the network card ip if 
there are huge amount of datas to pickup. On unix environments, using 
network card ip mean the datas  goes from memory to network card to 
wire, back to network driver, back to memory. Am not sure for wire part, 
but it's anyway a bottleneck you can avoid with 127.0.0.1 which is all 
in memory.

Last but not least, when you check cpu load, on unix environment, check
1) User CPU time (time taken by your application)
2) System CPU Time (time taken by kernel, as a result of application 
request, like accessing files)
3) Idel time (sleeping time of CPU, it's what is not used)

keglius a écrit :
> Hi, Chris!
>
> Thanks for your response!
> I can't say that the reporting function is a primary function of the server,
> however
> the web application includes a lot of statistical reports about
> views/visitors/sales, etc
> for long time periods (up to 1 year).
>
> As I told, the server has 2GBs of RAM. 1.6GB is constantly used, meaning
> that Tomcat
> uses only 800MB while the rest 800MB are used by the OS and other software
> running on the
> background. The memory is not used all because Tomcat is not allowed to use
> more than 800MBs.
> I guess it would easily eat up the remaining 400MB of free RAM. So, I would
> like to know if 
> increasing the Tomcat heap would help me to increase a server speed -
> application page
> loading speed?
>
> I guess the most slowest parts of the webapp (mostly statistical reporting
> section) relies 
> heavily on MySQL database, since it has to extract quite much data and call
> a lot of requests 
> to database in order to show the report.
>
> The Tomcat Java application and MySQL database runs on one machine, so I
> guess it's a one-box wonder.
>
> I performed tests on members area and found that in most cases all pages are
> loaded within 4-10 seconds.
> The slowest pages (e.g. reports to view longer period time data) sometimes
> takes 20-180 seconds to load.
>
> How can I increase this speed?
>
> Thanks,
> Keglius
>   


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How to increase Tomcat webserver speed?

Posted by Oliver Schoett <os...@sdm.de>.
keglius wrote:
> I performed tests on members area and found that in most cases all pages are
> loaded within 4-10 seconds.
> The slowest pages (e.g. reports to view longer period time data) sometimes
> takes 20-180 seconds to load.
>
> How can I increase this speed?
>   

The obvious approach is to find out where this time is actually spent.  
The safest approach is to proceed naively from the outside in, as follows.

First measure the loading performance of your Web page with Firebug 
(Firefox Plugin).  I will show you which web requests are responsible 
for the slowdown.

Assuming that server response times are responsible for the slowdown (as 
opposed to the data transfer to the browser), do a real-time profile of 
the server to find out where the time is spent, e. g. with the Eclipse 
TPTP or the Netbeans Profiler.  Using real-time profiling, you can 
detect whether the culprits are computations on the server or back-end 
calls (e. g., to the data base).

If server computations are the problem, the profiler will tell you the 
cause of the problem.

If the problem is in the back-end calls, there are two possibilities:

(a) The back-end calls consume a lot of time on the back-end server.  In 
this case you must look at the back-end server.  If it is a data base 
server, data base / query optimization must be performed.

(b) The data base calls do not consume a lot of time on the back-end 
server, but their sheer number causes the delays.  This requires a 
redesign of the back-end queries, such that the data is fetched with 
fewer calls.  For example, I have reviewed an application that performed 
15.000 DB calls to construct the response to a common user request.  No 
matter how efficient the calls on the data base, the latency of the 
15.000 calls will cause a response time in the tens of seconds, at least.

Thus, you can find out which of the four most common performance 
problems is responsible for your delays:

(1) Web performance, i. e., too many HTTP requests from the browser (not 
likely the case here),

(2) app server performance, i. e., too many computations,

(3) back end performance, i. e., too much work on the back end (e. g., 
the data base),

(4) back end call latency, i. e., too many separate back end calls.

It would be premature to start optimizing one of these before having 
identified the main cause of the problem.

Regards,

Oliver Schoett


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How to increase Tomcat webserver speed?

Posted by David kerber <dc...@verizon.net>.
Christopher Schultz wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> keglius,
>
> keglius wrote:
>   
>> So, I would like to know if increasing the Tomcat heap would help me
>> to increase a server speed - application page loading speed?
>>     
>
> No. More memory will simply allow you to handle more users. Unless your
> server is thrashing (which it might be), an increase in memory is
> unlikely to help.
>
>   
>> I guess the most slowest parts of the webapp (mostly statistical
>> reporting section) relies heavily on MySQL database, since it has to
>> extract quite much data and call a lot of requests to database in
>> order to show the report.
>>     
>
> I would get a DBA to look at your tables and make sure you have
> appropriate indexes, etc. to support those queries. Look for "slow"
> queries (that's a technical term, really), overly complex queries, or
> queries that you run many of that you might be able to reduce to fewer
> queries.
>
>   
>> The Tomcat Java application and MySQL database runs on one machine,
>> so I guess it's a one-box wonder.
>>     
>
> Yep, that's a one-box wonder.
>
>   
>> I performed tests on members area and found that in most cases all
>> pages are loaded within 4-10 seconds. The slowest pages (e.g. reports
>> to view longer period time data) sometimes takes 20-180 seconds to
>> load.
>>
>> How can I increase this speed?
>>     
>
> I'm guessing that your Java code is doing very little work, and that the
> database is basically doing everything. In that case, you have two
> possibilities:
>
> 1. Your queries/indexes suck and you need to adjust them appropriately.
>
> or
>
> 2. Your database needs are not being satisfied by your hardware.
>    You may need a beefier machine to do the kinds of reporting that you
>    are trying to do. More CPU power on a database never hurts, but what
>    a database really needs is memory, memory, and more memory. You
>    should get a good book on MySQL performance optimization and spend
>    some time reading it. You can adjust many things such as the query
>    cache, indexes, etc. If you have more memory, you can store more
>    index data in memory, which tends to speed things up dramatically.
>   

Memory and fast disk i/o.

D



---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How to increase Tomcat webserver speed?

Posted by Leon Rosenberg <ro...@googlemail.com>.
many interesting mails, but lacking advices :-)

i would hardly recommend you to actually measure your webapps performance.
You can use a filter to measure the request duration, and measure the
db call duration from your persistence service and by that determine
where the time is lost, db or tomcat. Whatever it is, you can
investigate further.
Most database system also offer sql statement duration logging, so you
can see which statements take how long.
It can be the markup generation, the io, the database pooling, a bad
synchronized block, inefficent loop somewhere or 1000 other possible
causes. You will know when you start to measure :-)
regards
Leon


On 10/5/07, Stephen Caine <st...@commongrnd.com> wrote:
> Keglius,
>
> Assuming you are using a web browser to display your data, consider
> the HTML used to construct the page.  Regardless of how fast your
> database is, using TABLEs will always be slower than just using PRE
> or BR tags.  While this may not be very pretty, it does result in
> much faster screen draws.  In some browsers, the table does not start
> drawing until the last record is transferred; while on others rows
> begin to appear as soon as the first record is transferred.
>
> The other suggestions, such as using indexes, will certainly help.
>
>  From our experience, with sufficient memory and CPU processing
> speed, Tomcat is very fast.
>
> Stephen Caine
> Soft Breeze Systems, LLC
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How to increase Tomcat webserver speed?

Posted by Stephen Caine <st...@commongrnd.com>.
Keglius,

Assuming you are using a web browser to display your data, consider  
the HTML used to construct the page.  Regardless of how fast your  
database is, using TABLEs will always be slower than just using PRE  
or BR tags.  While this may not be very pretty, it does result in  
much faster screen draws.  In some browsers, the table does not start  
drawing until the last record is transferred; while on others rows  
begin to appear as soon as the first record is transferred.

The other suggestions, such as using indexes, will certainly help.

 From our experience, with sufficient memory and CPU processing  
speed, Tomcat is very fast.

Stephen Caine
Soft Breeze Systems, LLC

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How to increase Tomcat webserver speed?

Posted by Hassan Schroeder <ha...@gmail.com>.
On 10/5/07, Christopher Schultz <ch...@christopherschultz.net> wrote:

> 1. Your queries/indexes suck and you need to adjust them appropriately.

+1 on that possibility :-)

I had a MySQL-based app that had slowed dramatically as the table
(product inventory) size grew.

Just changing some old-style queries, e.g.
  SELECT a, b, c FROM x, y, z WHERE...
to
  SELECT a, b, c FROM x LEFT JOIN y ON ...LEFT JOIN z ON ...
cut the query time from tens of seconds to sub-second.

If it's a possible problem with indexes, MySQL's EXPLAIN is helpful.

FWIW,
-- 
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How to increase Tomcat webserver speed?

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

keglius,

keglius wrote:
> So, I would like to know if increasing the Tomcat heap would help me
> to increase a server speed - application page loading speed?

No. More memory will simply allow you to handle more users. Unless your
server is thrashing (which it might be), an increase in memory is
unlikely to help.

> I guess the most slowest parts of the webapp (mostly statistical
> reporting section) relies heavily on MySQL database, since it has to
> extract quite much data and call a lot of requests to database in
> order to show the report.

I would get a DBA to look at your tables and make sure you have
appropriate indexes, etc. to support those queries. Look for "slow"
queries (that's a technical term, really), overly complex queries, or
queries that you run many of that you might be able to reduce to fewer
queries.

> The Tomcat Java application and MySQL database runs on one machine,
> so I guess it's a one-box wonder.

Yep, that's a one-box wonder.

> I performed tests on members area and found that in most cases all
> pages are loaded within 4-10 seconds. The slowest pages (e.g. reports
> to view longer period time data) sometimes takes 20-180 seconds to
> load.
> 
> How can I increase this speed?

I'm guessing that your Java code is doing very little work, and that the
database is basically doing everything. In that case, you have two
possibilities:

1. Your queries/indexes suck and you need to adjust them appropriately.

or

2. Your database needs are not being satisfied by your hardware.
   You may need a beefier machine to do the kinds of reporting that you
   are trying to do. More CPU power on a database never hurts, but what
   a database really needs is memory, memory, and more memory. You
   should get a good book on MySQL performance optimization and spend
   some time reading it. You can adjust many things such as the query
   cache, indexes, etc. If you have more memory, you can store more
   index data in memory, which tends to speed things up dramatically.

Hope that helps,
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHBnig9CaO5/Lv0PARAlywAJ9be6J1JDy4SASYKNQ2A7oHLQbQ9wCgm8Uz
fLPm/PmL1r5kanlRHXjZJjc=
=7nVo
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How to increase Tomcat webserver speed?

Posted by keglius <eg...@satnet.lt>.
Hi, Chris!

Thanks for your response!
I can't say that the reporting function is a primary function of the server,
however
the web application includes a lot of statistical reports about
views/visitors/sales, etc
for long time periods (up to 1 year).

As I told, the server has 2GBs of RAM. 1.6GB is constantly used, meaning
that Tomcat
uses only 800MB while the rest 800MB are used by the OS and other software
running on the
background. The memory is not used all because Tomcat is not allowed to use
more than 800MBs.
I guess it would easily eat up the remaining 400MB of free RAM. So, I would
like to know if 
increasing the Tomcat heap would help me to increase a server speed -
application page
loading speed?

I guess the most slowest parts of the webapp (mostly statistical reporting
section) relies 
heavily on MySQL database, since it has to extract quite much data and call
a lot of requests 
to database in order to show the report.

The Tomcat Java application and MySQL database runs on one machine, so I
guess it's a one-box wonder.

I performed tests on members area and found that in most cases all pages are
loaded within 4-10 seconds.
The slowest pages (e.g. reports to view longer period time data) sometimes
takes 20-180 seconds to load.

How can I increase this speed?

Thanks,
Keglius
-- 
View this message in context: http://www.nabble.com/How-to-increase-Tomcat-webserver-speed--tf4569998.html#a13053960
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How to increase Tomcat webserver speed?

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Keglius,

keglius wrote:
> I have a server running Apache Tomcat 5.5 with my Java application. This
> Java application uses MySQL 4.1.x and is very server resource intensive. The
> application makes a lot of calls to database to gather various information
> which is used for reports.

Is reporting the primary function of the server, or are you supporting
both a standard web application as well as reporting features? (I ask
because most companies offload reporting duties to a server that is not
used for day-to-day operations... the production server is replicated in
some way, and then a separate database is used for reporting.)

> My server is AMD 3200+ with 2GBs of RAM and 80gb hdd.

Seems fine. More memory is almost always better, but it shouldn't be a
problem if you're not running out of it.

> I would like to ask you, guys, how can I increase the speed of my Tomcat
> webserver, so the application would work faster?

As was mentioned less than an hour ago on another thread: if your web
app heavily relies on a database, then your database is likely to be the
bottleneck.

Is this a one-box wonder, or do you have the database on a separate
machine? Do you have appropriate indexes on your tables? Are you issuing
any "slow" queries (see MySQL documentation regarding identifying slow
queries)? Are you issuing barrages of queries that could potentially be
coalesced into just a few?

> Currently I ran a stress test with 10 users browsing through my application
> pages (members area) and I have noticed that it takes an average 5-10
> seconds to load the page. I need to increase the site loading speed much
> more, so the page loading would be much faster. The server load during the
> test was around 2.5% of CPU. System use 1.5 of RAM constantly (800MBs is
> allocated for Tomcat).

Is this one single page that is performing badly, or is this a
representative of the whole app?

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHBRpM9CaO5/Lv0PARAtmpAKCeHKdmULM/5QpVXxP9kxIHXxZ4LACguRn5
ZzGk5WqDsawVsEEx4g4VuKg=
=To0E
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org