HikariCP pool sizing in Grails 4+: fixed minimumIdle floor versus idle shrink for low-traffic workloads
0 reputation · 08 Feb 2021, 03:32 UTC
0 reputation · 08 Feb 2021, 03:32 UTC
Grails 4 and later default to HikariCP for GORM data sources, so low-traffic cost tuning is configured through dataSource.properties.* keys in application.yml rather than legacy Tomcat pool settings. The goal is to reduce database connection or session costs for a workload that sits idle for extended periods.
HikariCP interprets minimumIdle as a floor and maximumPoolSize as a ceiling. When both are set to the same low value, the pool remains fixed and does not release idle connections during quiet periods. Alternatively, setting minimumIdle below maximumPoolSize with a short idleTimeout allows the pool to shrink, though this can introduce connection churn and latency spikes on the first request after an idle gap. Because Grails 4, 5, and later inherit different Spring Boot and HikariCP versions, effective defaults and supported property names are version-sensitive and depend on the specific release in use.
The unresolved decision is whether to cap cost with a small fixed pool or accept extra acquisition latency after idle periods in exchange for surrendering idle connections. Which configuration boundary is appropriate for a low-traffic Grails application, and how should the trade-off be evaluated when the active implementation and resolved defaults differ across Grails versions?
35275 reputation · 08 Feb 2021, 04:04 UTC
For low-traffic Grails applications, a small fixed-size pool (where minimumIdle equals maximumPoolSize) is generally the superior choice. This configuration eliminates connection churn and prevents the latency spikes associated with TCP/TLS handshakes during the first request after an idle period.
The decision rests on whether the primary cost constraint is database session overhead or request latency:
minimumIdle after the idleTimeout expires. This is only recommended if the database has extremely strict session limits or if you are running hundreds of small micro-instances where aggregate idle connections would exhaust database resources.In Grails 4 and later, these settings are passed to HikariCP via the dataSource.properties map. To implement a stable, low-overhead fixed pool, use the following pattern:
dataSource:
properties:
maximumPoolSize: 5
minimumIdle: 5
idleTimeout: 600000
maxLifetime: 1800000
Because Grails versions inherit different Spring Boot and HikariCP releases, verify the actual resolved configuration using these steps:
SHOW PROCESSLIST in MySQL) during an idle period to confirm the connection count matches your minimumIdle.wait_timeout) is longer than HikariCP's maxLifetime to avoid "connection closed by peer" errors.Note: If you are using a cloud-managed database with aggressive connection killing, a dynamic pool may actually increase error rates unless keepaliveTime is also configured.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.