Tomcat sessions memory usage and MySQL connections

R

romanlutsk

Dear all,
We run a tomcat/mysql web portal that generates a lot of queries to
mysql server.
Recently after letting more users use the portal, we've started
experiencing freezing of the web server (java or mysql processes take
up to 99% of cpu).

This problem has stopped after increasing a number of mysql connections
from 100 to 400 and allocating 128 MB of memory to tomcat.

However, now mysql seems to have too many connections all the time. It
constantly shows around 300-350 connections. Also, when trying to
execute a larger SQL, it returns this error:

************
#1037 - Out of memory. Restart daemon and try again (needed 32768
bytes)
************
I've checked the application, the database connections and resultSets
are closed everywhere, so there shouldn't be any memory leak in the app
itself.

On the other side, tomcat seems to have a lot of unused sessions open,
over 150 sessions that are inactive for over 30 minutes.

We've tried to set worker.tc1.recycle_timeout=120 in
apache/conf/workers.properties, but it doesn't seem to help. Tomcat
shows the following:

OK - Session-Information for applications in context path /fhoportal
Sessions end after 30 minutes of inactivity
10 - <20 Minutes: 11 Sessions
30 - <40 Minutes: 105 Sessions

OK - Session-Information for applications in context path /uportal
Sessions end after 30 minutes of inactivity
10 - <20 Minutes: 1 Sessions
30 - <40 Minutes: 41 Sessions

Tomcat 4.0 is connected with apache through mode_jk. Tomcat/apache and
mysql run on the same server with 2 Xenon processors and 1 GB of RAM.
Mysql version is 4.0.18.
OS is SuSE 9.0 Enterprise edition

I wonder anyone could give any pointers on where to look for a
solution.

It looks like the mysql connections or tomcat sessions are not being
closed. However, the server runs for about 10 days now and the number
of mysql connections stays at around 360 all the time.
Is it not supposed to go up and down in real time, as the number of
users increase and decrease? We don't use any connection pooling.

Also, I wonder what exactly the tomcat sessions are? Are those the
sessions that users start from their browsers when they login into the
system? If yes, why are there so many inactive sessions?
Could this indicate a problem?

Thank you very much,
Roman Zhovtulya
 
I

Ingo R. Homann

Hi,

I've checked the application, the database connections and resultSets
are closed everywhere, so there shouldn't be any memory leak in the app
itself.

Hmmm... so you mean something like that?:

Connection con=...
Statement stmt=...
ResultSet rs=...
....
rs.close();
stmt.close();
con.close();

Or do you really do it the following way?:

Connection con=null;
Statement stmt=null;
ResultSet rs=null;
try {
...
} finally {
if(rs!=null) {
rs.close();
}
if(stmt!=null) {
stmt.close();
}
if(conn!=null) {
conn.close();
}
}

You get waht I mean? If - in the first code-snippet - an exception is
thrown, the resources are *NOT* closed!

We have an application in which we store for every Connection where
(complete StackTrace!) it was created.

If the Connection is garbage collected and was not closed before, we can
log the Stacktrace and so see where the error is. I would suggest yout
to so the same!

Ciao,
Ingo
 
K

kevins

************
#1037 - Out of memory. Restart daemon and try again (needed 32768
bytes)
************
I would also check the mysql database, problems like 'too many
connections' or 'out of memory' can be caused by a corrupt table in the
mysql master database. It could also be the cause of why you have so
many connections open even though you're not using connection pooling.
It looks like the mysql connections or tomcat sessions are not being
closed. However, the server runs for about 10 days now and the number
of mysql connections stays at around 360 all the time.
Is it not supposed to go up and down in real time, as the number of
users increase and decrease? We don't use any connection pooling.


Also, I wonder what exactly the tomcat sessions are? Are those the
sessions that users start from their browsers when they login into the
system? If yes, why are there so many inactive sessions?
Could this indicate a problem?
A session is a started when the user open their browser and it is a
thread in Tomcat. Session lifetime is usually 20 minutes by default.
You can shorten this or increase the rate at which Tomcat deactivates
session.
Check
http://tomcat.apache.org/tomcat-4.1-doc/config/manager.html

K Saunders
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,967
Messages
2,570,148
Members
46,694
Latest member
LetaCadwal

Latest Threads

Top