Why WSO2 APIm needs 50+ DB connections at startup?

12/3/2020

In our WSO2 setup, whenever the APIm comes up, it creates close to 50+ DB connections towards the PostGres DB. In stable phase, each APIm instance has only 4 DB connections. I would like to understand why it needs 50+ connections at startup? is it a bug or by design?

We run WSO2 in kubernetes setup, PostGres has a max connection limit set to 100, and two instances of APIm is not able to come-up due to this issue.

-- Ganesh Natarajan
apim
kubernetes
wso2

1 Answer

2/18/2021

Within the WSO2 platform, the Tomcat JDBC pooling is used as the default pooling framework due to its production-ready stability and high performance. The goal of tuning the pool properties is to maintain a pool that is large enough to handle peak load without unnecessarily utilizing resources. These pooling configurations can be tuned for your production server in general in the <PRODUCT_HOME>/repository/conf/datasources/master-datasources.xml file. This is applicable if you are using an APIM version less than or equal to 2.6. If you are using APIM-3.X.X then these configurations can be found in <PRODUCT_HOME>/repository/conf/deployment.toml file.

The following parameters should be considered when tuning the connection pool:

  • The application's concurrency requirement.
  • The average time used for running a database query.
  • The maximum number of connections the database server can support.

The maxActive value is the maximum number of active connections that can be allocated from the connection pool at the same time. The default value is 100. The maximum latency (approximately) = (P / M) * T, where,

M = maxActive value
P = Peak concurrency value
T = Time (average) taken to process a query

Therefore, by increasing the maxActive value (up to the expected highest number of concurrency), the time that requests wait in the queue for a connection to be released will decrease. But before increasing the Max. Active value, consult the database administrator, as it will create up to maxActive connections from a single node during peak times, and it may not be possible for the DBMS to handle the accumulated count of these active connections.

Note that this value should not exceed the maximum number of requests allowed for your database.

For more details on this topic please refer to the official documents1, 2.

1 https://docs.wso2.com/display/ADMIN44x/Performance+Tuning#PerformanceTuning-JDBCpoolconfiguration

2 http://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html

-- Saranki Magenthirarajah
Source: StackOverflow