brettwooldridge / HikariCP

光 HikariCP・A solid, high-performance, JDBC connection pool at last.
Apache License 2.0
20.01k stars 2.93k forks source link

Play: Restart on code change takes long to shutdown and starting the Hikary Pool #1488

Open pme123 opened 5 years ago

pme123 commented 5 years ago

Environment

HikariCP version: 3.3.1 (Play Framework 2.7)
JDK version     : 1.8.0_*
Database        : PostgreSQL
Driver version  : 42.2.8

I use the Play Default configuration for the Pools: https://www.playframework.com/documentation/2.7.x/SettingsJDBC#Reference

I have multiple Datasources when restarting during development the shutdown of some Pools take about 10 seconds. Most of them shutdown immediately.

image

It makes development a pain.

Is there a way to speed this up? For example share the pools between datasources.

I created also a Stackoverflow question: https://stackoverflow.com/questions/58639422/play-restart-on-code-change-takes-long-to-shutdown-and-starting-the-hikary-pool

billoneil commented 5 years ago

It looks like you have a single application with greater than 55 connection pools. Is that accurate? Why does one application connect to so many databases? How many connections is each pool allowed to have?

billoneil commented 5 years ago

You mentioned you are using Play's default config settings for HikariCP. By default, it will initialize each pool you have with 10 database connections. So it needs to teardown and establish 10 connections per pool on every restart.

Try setting minimumIdle to 1 (in development mode) which will only create a single connection per datasource and scale up as needed lazily.

pme123 commented 5 years ago

Thanks with your input we know could get closer to the problem.

We have indeed lots of datasources, as the application serves different customers (tenants) and each of them can have a number of databases.

The problem are now datasources where the database is not reachable (during development). So we configured it, that the application also starts when the database is not reachable (initializationFailTimeout = -1).

So there are 2 problems when shutting down:

So concrete the question is now can we influence these properties or do we need another configuration for development?

billoneil commented 5 years ago

Instead of having them ignore failure to initialize can you make those datasources load lazily? That way it will only try to connect to the database the first time you access it.

pme123 commented 5 years ago

That seems to work, I have some checks to do, the only thing at the moment is this error in the log file:

2019-11-12 17:48:50,969 [info] application - Creating Pool for datasource 'mydatabase'
2019-11-12 17:48:50,969 [error] c.z.h.HikariConfig - HikariPool-96 - dataSource or dataSourceClassName or jdbcUrl is required.

This happens when shutting down - what is a bit odd.

But no time lost for that.