Tomcat 8 MySQL at most 8 connections seen in MySQL Workbench from each tomcat instace

Problem:

JDBC connection pool does not seem to have the desired number of initial connections.

It also does not grow to the maximum allowed (at most 8 connections appear to be open per Tomcat instance) thus many clients are blocked waiting for a sql connection

For each Tomcat instance I have a maximum of 8 connections seen on the sql server when using this command:

show processlist;

If I set the initialSize to anything under 8 then tomcat will create that number of connections

  • initialSize == 1 - at Tomcat startup 1 connections are created
  • initialSize == 5 - at Tomcat startup 5 connections are created
  • initialSize >= 9 - at Tomcat startup 8 connections are created

The connections that exist are functional and the application works while there are few enough requests from clients

In server.xml:

        <Resource auth="Container"
            driverClassName="com.mysql.jdbc.Driver"
            closeMethod="close"
            validationInterval="34000"
            maxWait="3000"
            initialSize="50"
            name="XXX"
            password="XXX"
            removeAbandoned="true"
            removeAbandonedTimeout="350" testWhileIdle="true"
            type="javax.sql.DataSource"
            url="jdbc:mysql://XXXXXXX:3306/XXXXX?characterEncoding=UTF-8"
            username="XXX"
            removeAbandonedOnBorrow="true"
            removeAbandonedOnMaintenance="true"
            validationQuery="SELECT 1"
        />

Additional information show global variables like '%connections%';

  • max_connections 1000
  • max_user_connections 0
Jon Skeet
people
quotationmark

It sounds like you just need to set the maxTotal configuration option too, e.g.

maxTotal="50"

I say this based on the DBCP configuration documentation:

Parameter: maxTotal
Default: 8
Description: The maximum number of active connections that can be allocated from this pool at the same time, or negative for no limit.

If you've got a maximum total of 8, I'm not surprised that increasing the initial beyond 8 doesn't make any difference.

You may well want to set maxIdle as well.

people

See more on this question at Stackoverflow