0

I recently switched my Spring RESTful API data source from DriverManagerDataSource to HikariCp, but my database connections went from 20 connections to 600 connections. Is this suppose to happen?

My settings are as follows:

<bean id="jdbcDataSource"
    class="com.zaxxer.hikari.HikariDataSource" destroy-method="shutdown">
    <constructor-arg>
        <bean class="com.zaxxer.hikari.HikariConfig">
            <constructor-arg>
                <props>
                    <prop key="dataSource.url">url</prop>
                    <prop key="dataSource.user">user</prop>
                    <prop key="dataSource.password">password</prop>
                    <prop key="dataSource.cachePrepStmts">true</prop>
                    <prop key="dataSource.prepStmtCacheSize">250</prop>
                    <prop key="dataSource.prepStmtCacheSqlLimit">2048</prop>
                    <prop key="dataSource.useServerPrepStmts">true</prop>
                </props>
            </constructor-arg>
            <property name="dataSourceClassName" value="com.mysql.jdbc.jdbc2.optional.MysqlDataSource" />
        </bean>
    </constructor-arg>
</bean>

<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
    <property name="dataSource" ref="jdbcDataSource" />
</bean>
Hank
  • 3,367
  • 10
  • 48
  • 86
  • It's not supposed to happen. What version of HikariCP are you using? – brettw Mar 24 '14 at 01:21
  • The change log for 1.3.3 says "Fixed issue where the maximum configured connections could be overrun during large burst requests for connections." – brettw Mar 24 '14 at 01:33
  • I'm using version 1.3.3 – Hank Mar 24 '14 at 03:53
  • Are you running something to generate load? Any exceptions in the log? – brettw Mar 24 '14 at 04:02
  • I have a lot of scripts accessing my API that send a lot of INSERT requests. And there are no exceptions in the logs – Hank Mar 24 '14 at 04:18
  • I'm one of the core authors of HikariCP, something is definitely strange. I've opened a [tracking defect](https://github.com/brettwooldridge/HikariCP/issues/49) over on GitHub where it should be easier to attach logs, etc. Can you turn on debug logging for the ``com.zaxxer.hikari`` package? The pool should log statistics every 30 seconds, and possibly additional operational logs. – brettw Mar 24 '14 at 05:10
  • How do I turn on logging? – Hank Mar 24 '14 at 05:22
  • Spring is probably using log4j or slf4j. There should be a properties file or XML configuration somewhere for logging. For log4j normally you would use something like ``log4j.logger.com.zaxxer.hikari=DEBUG``. – brettw Mar 24 '14 at 05:33
  • If you want to see actual open MySQL connections, use ``SHOW STATUS WHERE `variable_name` = 'Threads_connected';`` from the mysql command shell. Running a command like ``show status like 'Con%';`` shows total connection attempts (successful and unsuccessful) over the lifetime of the MySQL server. – brettw Mar 24 '14 at 05:40

1 Answers1

2

I have been unable to reproduce your problem with HikariCP version 1.3.3. I'm not sure how you are measuring connections at the database, but users often check the wrong metric. Use:

SHOW STATUS WHERE `variable_name` = 'Threads_connected';

instead of:

SHOW STATYS LIKE 'Con%';

which is often mistakenly used.

brettw
  • 10,664
  • 2
  • 42
  • 59