October 22, 2024
Chicago 12, Melborne City, USA
java

HikariCP-Oracle Connection Pool Recreated on Every Invocation in Java Micronaut Azure Function


I’m working on a Java application built with the Micronaut framework that leverages Azure Functions for a serverless design. The application connects to an Oracle database. However, I’ve encountered an issue where a new connection pool is being created on every single function invocation. This leads to a rapid increase in the number of active database processes, eventually exceeding the max processes limit on the Oracle DB side.

Here’s the behavior I’m seeing:

  • The connection pool size is set to 10.
  • For each invocation of the function, a new connection pool with 10
    connections is created, causing a spike in the number of processes on
    the database.

For comparison, I have another application with a similar setup but written in Spring Boot, and it doesn’t face this issue. In Spring Boot, the connection pool is reused across invocations, and the pool size remains stable at 10, as expected.

Question:

  1. Is there a way to configure a Micronaut application to reuse a
    single connection pool across function invocations, similar to how
    it works in Spring Boot?

  2. How can I prevent Micronaut from creating a new connection pool with
    every invocation in this serverless context?

I’m using HikariCP as the pool provider.

Here is the dependencies I’m using,

<dependency>
  <groupId>io.micronaut.sql</groupId>
  <artifactId>micronaut-jdbc-hikari</artifactId>
  <scope>compile</scope>
</dependency>
<dependency>
  <groupId>io.micronaut.data</groupId>
  <artifactId>micronaut-data-hibernate-jpa</artifactId>
  <version>4.7.1</version>
</dependency>
<dependency>
  <groupId>io.micronaut.data</groupId>
  <artifactId>micronaut-data-tx-hibernate</artifactId>
  <version>4.8.4</version>
</dependency>
<dependency>
  <groupId>com.oracle.database.jdbc</groupId>
  <artifactId>ojdbc10</artifactId>
  <version>19.23.0.0</version>
</dependency>

I’m seeing the following logs for each invocation,

[2024-10-17T03:36:31.767Z] [36m09:06:31.766[0;39m [1;30m[pool-2-thread-2][0;39m [34mINFO [0;39m [35mcom.zaxxer.hikari.pool.HikariPool[0;39m - HikariPool-1 - Added connection oracle.jdbc.driver.T4CConnection@42b52ad3
[2024-10-17T03:36:31.768Z] [36m09:06:31.767[0;39m [1;30m[pool-2-thread-2][0;39m [34mINFO [0;39m [35mcom.zaxxer.hikari.HikariDataSource[0;39m - HikariPool-1 - Start completed.
[2024-10-17T03:36:31.778Z] [36m09:06:31.777[0;39m [1;30m[pool-2-thread-2][0;39m [34mINFO [0;39m [35mi.m.l.PropertiesLoggingLevelsConfigurer[0;39m - Setting log level 'TRACE' for logger: 'com.zaxxer.hikari'
[2024-10-17T03:36:31.778Z] [36m09:06:31.777[0;39m [1;30m[pool-2-thread-2][0;39m [34mINFO [0;39m [35mi.m.l.PropertiesLoggingLevelsConfigurer[0;39m - Setting log level 'TRACE' for logger: 'io.micronaut.http'
[2024-10-17T03:36:31.778Z] [36m09:06:31.777[0;39m [1;30m[pool-2-thread-2][0;39m [34mINFO [0;39m [35mi.m.l.PropertiesLoggingLevelsConfigurer[0;39m - Setting log level 'TRACE' for logger: 'io.micronaut.http.client'
[2024-10-17T03:36:31.881Z] [36m09:06:31.880[0;39m [1;30m[HikariPool-1 housekeeper][0;39m [39mDEBUG[0;39m [35mcom.zaxxer.hikari.pool.HikariPool[0;39m - HikariPool-1 - Pool stats (total=1, active=0, idle=1, waiting=0)
[2024-10-17T03:36:34.473Z] [36m09:06:34.472[0;39m [1;30m[HikariPool-1 connection adder][0;39m [39mDEBUG[0;39m [35mcom.zaxxer.hikari.pool.HikariPool[0;39m - HikariPool-1 - Added connection oracle.jdbc.driver.T4CConnection@620baa8d
[2024-10-17T03:36:34.509Z] [36m09:06:34.509[0;39m [1;30m[HikariPool-1 connection adder][0;39m [39mDEBUG[0;39m [35mcom.zaxxer.hikari.pool.HikariPool[0;39m - HikariPool-1 - After adding stats (total=2, active=0, idle=2, waiting=0)
[2024-10-17T03:36:35.999Z] InvocationId : fa90e899-7dd9-478f-b057-6067e3d9d688
[2024-10-17T03:36:36.010Z] [36m09:06:36.009[0;39m [1;30m[pool-2-thread-2][0;39m [39mTRACE[0;39m [35mi.m.http.server.RequestLifecycle[0;39m - Matched route POST - /api/v1/login to controller class io.micronaut.security.endpoints.LoginController
[2024-10-17T03:36:36.068Z] [36m09:06:36.068[0;39m [1;30m[pool-2-thread-2][0;39m [39mTRACE[0;39m [35mi.m.http.server.cors.CorsFilter[0;39m - Http Header Origin not present. Proceeding with the request.
[2024-10-17T03:36:36.069Z] [36m09:06:36.068[0;39m [1;30m[pool-2-thread-2][0;39m [39mTRACE[0;39m [35mi.m.http.server.cors.CorsFilter[0;39m - Http Header Origin not present. Proceeding with the request.
[2024-10-17T03:36:36.841Z] [36m09:06:36.840[0;39m [1;30m[HikariPool-1 connection adder][0;39m [39mDEBUG[0;39m [35mcom.zaxxer.hikari.pool.HikariPool[0;39m - HikariPool-1 - Added connection oracle.jdbc.driver.T4CConnection@2d3f4add
[2024-10-17T03:36:36.878Z] [36m09:06:36.878[0;39m [1;30m[HikariPool-1 connection adder][0;39m [39mDEBUG[0;39m [35mcom.zaxxer.hikari.pool.HikariPool[0;39m - HikariPool-1 - After adding stats (total=3, active=1, idle=2, waiting=0)
[2024-10-17T03:36:39.249Z] [36m09:06:39.248[0;39m [1;30m[HikariPool-1 connection adder][0;39m [39mDEBUG[0;39m [35mcom.zaxxer.hikari.pool.HikariPool[0;39m - HikariPool-1 - Added connection oracle.jdbc.driver.T4CConnection@55bc76e8
[2024-10-17T03:36:39.294Z] [36m09:06:39.293[0;39m [1;30m[HikariPool-1 connection adder][0;39m [39mDEBUG[0;39m [35mcom.zaxxer.hikari.pool.HikariPool[0;39m - HikariPool-1 - After adding stats (total=4, active=1, idle=3, waiting=0)
[2024-10-17T03:36:39.781Z] Function "PsoHttpTrigger" (Id: fa90e899-7dd9-478f-b057-6067e3d9d688) invoked by Java Worker
[2024-10-17T03:36:39.834Z] Executed 'Functions.PsoHttpTrigger' (Succeeded, Id=fa90e899-7dd9-478f-b057-6067e3d9d688, Duration=12121ms)
[2024-10-17T03:36:41.651Z] [36m09:06:41.650[0;39m [1;30m[HikariPool-1 connection adder][0;39m [39mDEBUG[0;39m [35mcom.zaxxer.hikari.pool.HikariPool[0;39m - HikariPool-1 - Added connection oracle.jdbc.driver.T4CConnection@4eb898e0
[2024-10-17T03:36:41.682Z] [36m09:06:41.681[0;39m [1;30m[HikariPool-1 connection adder][0;39m [39mDEBUG[0;39m [35mcom.zaxxer.hikari.pool.HikariPool[0;39m - HikariPool-1 - After adding stats (total=5, active=0, idle=5, waiting=0)
[2024-10-17T03:36:44.200Z] [36m09:06:44.200[0;39m [1;30m[HikariPool-1 connection adder][0;39m [39mDEBUG[0;39m [35mcom.zaxxer.hikari.pool.HikariPool[0;39m - HikariPool-1 - Added connection oracle.jdbc.driver.T4CConnection@6fbf0cf2
[2024-10-17T03:36:44.231Z] [36m09:06:44.230[0;39m [1;30m[HikariPool-1 connection adder][0;39m [39mDEBUG[0;39m [35mcom.zaxxer.hikari.pool.HikariPool[0;39m - HikariPool-1 - After adding stats (total=6, active=0, idle=6, waiting=0)
[2024-10-17T03:36:46.761Z] [36m09:06:46.760[0;39m [1;30m[HikariPool-1 connection adder][0;39m [39mDEBUG[0;39m [35mcom.zaxxer.hikari.pool.HikariPool[0;39m - HikariPool-1 - Added connection oracle.jdbc.driver.T4CConnection@5f294954
[2024-10-17T03:36:46.792Z] [36m09:06:46.791[0;39m [1;30m[HikariPool-1 connection adder][0;39m [39mDEBUG[0;39m [35mcom.zaxxer.hikari.pool.HikariPool[0;39m - HikariPool-1 - After adding stats (total=7, active=0, idle=7, waiting=0)
[2024-10-17T03:36:49.643Z] [36m09:06:49.642[0;39m [1;30m[HikariPool-1 connection adder][0;39m [39mDEBUG[0;39m [35mcom.zaxxer.hikari.pool.HikariPool[0;39m - HikariPool-1 - Added connection oracle.jdbc.driver.T4CConnection@7af83c22
[2024-10-17T03:36:49.674Z] [36m09:06:49.673[0;39m [1;30m[HikariPool-1 connection adder][0;39m [39mDEBUG[0;39m [35mcom.zaxxer.hikari.pool.HikariPool[0;39m - HikariPool-1 - After adding stats (total=8, active=0, idle=8, waiting=0)
[2024-10-17T03:36:52.201Z] [36m09:06:52.200[0;39m [1;30m[HikariPool-1 connection adder][0;39m [39mDEBUG[0;39m [35mcom.zaxxer.hikari.pool.HikariPool[0;39m - HikariPool-1 - Added connection oracle.jdbc.driver.T4CConnection@2932f35f
[2024-10-17T03:36:52.232Z] [36m09:06:52.231[0;39m [1;30m[HikariPool-1 connection adder][0;39m [39mDEBUG[0;39m [35mcom.zaxxer.hikari.pool.HikariPool[0;39m - HikariPool-1 - After adding stats (total=9, active=0, idle=9, waiting=0)
[2024-10-17T03:36:54.761Z] [36m09:06:54.760[0;39m [1;30m[HikariPool-1 connection adder][0;39m [39mDEBUG[0;39m [35mcom.zaxxer.hikari.pool.HikariPool[0;39m - HikariPool-1 - Added connection oracle.jdbc.driver.T4CConnection@8b2f707
[2024-10-17T03:36:54.799Z] [36m09:06:54.798[0;39m [1;30m[HikariPool-1 connection adder][0;39m [39mDEBUG[0;39m [35mcom.zaxxer.hikari.pool.HikariPool[0;39m - HikariPool-1 - After adding stats (total=10, active=0, idle=10, waiting=0)

Any advice or insights would be greatly appreciated!



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video