When a Spring Boot application running on Red Hat OpenShift 4 suddenly stops serving traffic due to exhausted or hung database connections, default HikariCP configurations are often the culprit. Here is how to configure, monitor, and troubleshoot Hikari connection pools to survive network drops and container CPU throttling.
If you are already running Spring Boot on Red Hat OpenShift, you might have tackled Java Virtual Machine (JVM) memory tuning and Red Hat Data Grid integration (see Integrate a Spring Boot application with Red Hat Data Grid and How to troubleshoot Spring Boot in OpenShift). This guide focuses on the layer in between: how Hikari manages database connections under container constraints.
Hikari use in Spring Boot
You can configure Hikari in Spring Boot through application.properties
, for example:
# Database Connection Settings
spring.datasource.url=jdbc:postgresql://localhost:5432/db
spring.datasource.username=dbuser
spring.datasource.password=dbpass
spring.datasource.driver-class-name=org.postgresql.Driver
# HikariCP Specific Settings
# Fixed pool size (Recommended for high-load/SDN environments)
spring.datasource.hikari.minimum-idle=20
spring.datasource.hikari.maximum-pool-size=20
# Timeouts and Lifecycle
spring.datasource.hikari.idle-timeout=300000
spring.datasource.hikari.max-lifetime=1800000
spring.datasource.hikari.connection-timeout=30000
spring.datasource.hikari.validation-timeout=5000
# Monitoring & Debugging
spring.datasource.hikari.pool-name=InfinispanAuditHikariPool
spring.datasource.hikari.leak-detection-threshold=5000
You can also configure a DataSource
bean programmatically in Java:
@Configuration
public class DataSourceConfig {
@Bean
@ConfigurationProperties("spring.datasource.hikari")