mysqlslickhikaricpconnector-j

Managing MySQL connections using HikariCP and Slick


I'm running a Scala application on this software stack:

Mac OS X 10.6.8 Snow Leopard
MySQL 5.1.46
Java 1.6.0_65
Scala 2.11.2
ConnectorJ 5.1.33
HikariCP 2.1.0
Slick 2.1.0

I cannot get why open connections to MySQL keep staying open even after shutting the Scala app down. The only correct aspect is that the Threads_connected drops from 16 down to 1 (that is the console from which I'm executing the 'show status' command.

mysql> show status like '%onn%';
+--------------------------+-------+
| Variable_name            | Value |
+--------------------------+-------+
| Aborted_connects         | 0     |
| Connections              | 77    |
| Max_used_connections     | 19    |
| Ssl_client_connects      | 0     |
| Ssl_connect_renegotiates | 0     |
| Ssl_finished_connects    | 0     |
| Threads_connected        | 1     |
+--------------------------+-------+
7 rows in set (0.00 sec)

The strange thing is I always see the open connections to the DB growing up by the maximum number of open connections set in the connection pool (HikariCP maximumPoolSize) every time I run the app hence I can state the connections are never given back to the connection pool for reuse.

According to Slick documentation using

db withSession { implicit session => 
 /* entering the scope, getting 1 conn from the pool */
 /* 
  do something within the session using the connection I've gotten
 */
}
/* here I'm out of the 'withSession' scope, and the 
   connection should be released */

will take a connection from the pool when entering its scope and will release it just out of the scope

Am I doing something wrong or did I get something wrong about connection pool usage on this software stack?


Solution

  • Connections is a counter of how many connection attempts have been made since the last time you started mysqld. This counter always increases; it does not decrease when the connections end.

    That counter is not the number of current connections -- that's Threads_connected.