| | 256 | == Pooling |
| | 257 | In the backend layer of the Petify application, we use Spring Boot with Spring Data JPA to communicate with the PostgreSQL database. Because of this architecture, database connections are not created manually. Instead, they are automatically managed by HikariCP, which is the default connection pool implementation in Spring Boot. |
| | 258 | [[BR]] |
| | 259 | HikariCP is included transitively through: |
| | 260 | {{{spring-boot-starter-data-jpa}}} |
| | 261 | [[BR]] |
| | 262 | Therefore, no additional configuration is required to enable pooling. |
| | 263 | [[BR]] |
| | 264 | In this project, we use these HikariCP configuration values: |
| | 265 | {{{ |
| | 266 | spring.datasource.hikari.maximum-pool-size=20 |
| | 267 | spring.datasource.hikari.minimum-idle=5 |
| | 268 | spring.datasource.hikari.connection-timeout=20000 |
| | 269 | spring.datasource.hikari.idle-timeout=300000 |
| | 270 | spring.datasource.hikari.max-lifetime=1200000 |
| | 271 | spring.datasource.hikari.auto-commit=true |
| | 272 | }}} |
| | 273 | These values mean: |
| | 274 | * A maximum of 20 database connections can be active at the same time. |
| | 275 | * The pool maintains 5 idle connections ready for immediate use. |
| | 276 | * If all connections are busy, a request waits up to 20 seconds before failing. |
| | 277 | * Idle connections are kept alive for up to 5 minutes. |
| | 278 | * Connections are refreshed every 20 minutes to avoid stale connections. |
| | 279 | * Auto-commit is enabled by default. |