0

We are using r2dbc-pool for our application, along with Jooq. The ConnectionFactory is as follows

ConnectionFactoryOptions.Builder connectionFactoryBuilder = ConnectionFactoryOptions.builder();
connectionFactoryBuilder.option(ConnectionFactoryOptions.HOST, ....)
    .option(ConnectionFactoryOptions.DRIVER, "pool")
    .option(ConnectionFactoryOptions.PROTOCOL, "postgres")
    .option(ConnectionFactoryOptions.DATABASE, ....)
    .option(ConnectionFactoryOptions.USER, username)
    .option(ConnectionFactoryOptions.PASSWORD, password);
return ConnectionFactories.get(connectionFactoryBuilder.build());

The ConnectionPoolConfiguration looks something like this

ConnectionPoolConfiguration configuration = ConnectionPoolConfiguration.builder(<connection-factory>)
   .initialSize(10)
   .maxCreateConnectionTime(Duration.ofSeconds(30))
   .maxAcquireTime(Duration.ofSeconds(30))
   .acquireRetry(3)
   .maxSize(20)
   .build();

We were constantly getting Connection acquisition timed out after 30000ms. We suspected that maybe the load was too much for the connection and decided to log the PoolMetrics exposed by ConnectionPool.getMetrics()

The code we had to get connection looks something like this

public Single<Connection> getConnection(ConnectionPool connectionPool) {
    Optional<PoolMetrics> poolMetricsOptional = connectionPool.getMetrics();
    poolMetricsOptional.ifPresent(
        poolMetrics -> log.info("Connection Pool before acquiring connection: {}", poolMetrics)
    );
    Single<Connection> connectionSingle = Single.fromPublisher(connectionPool.create());
    Optional<PoolMetrics> poolMetricsOptional = connectionPool.getMetrics();
    poolMetricsOptional.ifPresent(
        poolMetrics -> log.info("Connection Pool after acquiring connection: {}", poolMetrics)
    );
    return connectionSingle;

When we started hitting the timeout the logs looked something like this

Connection Pool before acquiring connection: Acquire Size: 1, Allocated Size: 20, Idle Size: 9, Pending Acquire Size: 0
Connection Pool after acquiring connection: Acquire Size: 1, Allocated Size: 20, Idle Size: 9, Pending Acquire Size: 0

I have two doubts:

  1. Shouldn't acquire size + idle size be equal to allocated size?
  2. Any idea why isn't the connection being acquired despite the idle connections?

Version details are as follows r2dbc-pool: 0.9.1.RELEASE r2dbc-postgresql: 0.9.0.RELEASE

SantaClara
  • 86
  • 1
  • 9
  • Hi did you get any solution to this issue. I am having a similar issue at my end. It would be great if you can point me to some direction. – Naman Nov 20 '22 at 18:17

0 Answers0