0

I have responsibility for a legacy Tomcat webapp running as webapps/ROOT. Previously the app was running on a dedicated Linux server, but to save money I was asked to move it to a different Linux server where it shares a MySQL database with a few PHP apps. They are all fed through Apache 2 using VirtualHosts.

Since moving over, the Tomcat app seems to ocassionally "consume" all database connections to the point where the Tomcat app won't respond to requests, but the PHP apps on the server will also not respond to requests. A restart of Tomcat resolves the problem.

Currently, my hack is to set up a cron job to bounce Tomcat every evening. This is reduced the number of these incidents, but they still occur occasionally.

In this app, the database connection is defined in server.xml. I've tried modifying maxActive. Originally, it was set to 99, but I changed to -1 but it didn't seem to help one way or the other.

<Resource name="jdbc/theApp" auth="Container"
          type="javax.sql.DataSource"
          username="tomcat"
          password="thePassword"
          driverClassName="com.mysql.jdbc.Driver"
          url="jdbc:mysql://localhost:3306/theApp?autoReconnect=true"
          maxActive="-1"
          maxIdle="20"
          maxWait="3000"
          removeAbandoned="true"
          removeAbandonedTimeout="300"
          logAbandoned="true"/> 

Question: Has anyone seen this? If not, is there a way to help diagnose what is going wrong? The original development team is not available.

1 Answer 1

1

I've seen several situations where two different apps end up fighting for mysql connection pool resources. Most times it can be resolved with mysql tuning, but in some cases it is an issue with an app that has to be resolved.

Looking at things like the mysql cli SHOW PROCESSLIST command will give you an idea what the connection pool is doing. I'd also look at the excellent mysql tuning primer script to get an idea of the mysql environment. Its tracked here: http://forge.mysql.com/projects/project.php?id=44

If you really just want to limit the damage the tomcat app can do, you can always set the maximum connections of the container to a number smaller than the max_connections variable for mysql.

2
  • Good point... If both the PHP apps and Tomcat are trying to access the same database tables it could also be a locking issue that the processlist could potentially point to. Dec 6, 2009 at 19:58
  • Thank you for your response. I've been trying to monitor processes and tail logs and I'm starting to wonder if I've misdiagnosed the problem. When the blocking occurs, I can't access even static content through Apache. I wonder if I simply need to try and increase MaxClients in my mpm_worker_module (or mpm_prefork_module, I'm still researching the difference) or, as I saw in a different post, reduce the KeepAlive time. Thanks again!
    – GSP
    Dec 8, 2009 at 19:04

You must log in to answer this question.