-1

We are using Apache DBCP 1.4 for database connection pooling, with Java back-end, in our application. We set the value for maxActive = 20(by default), there was a scenario where requests needed more than 20 connection for execution. At that time application gets hang/unresponsive.

I have increased the value to maxActive = 50. Then execution completes successfully. In documentation of Apache DBCP, I have seen we can put the value of maxActive = -1, and this will not set upper limit on connection creation. Can I set maxActive = -1, if not can you please help me understand why it is not desirable and also what can be descent value we can set for maxActive so that my application do not gets hang/unresponsive.

final BasicDataSource basicDataSource = new BasicDataSource(); 

basicDataSource.setUrl(url);
basicDataSource.setUsername(user);
basicDataSource.setPassword(password);
basicDataSource.setDriverClassName(driver);

if (driver.contains("oracle")) {
  basicDataSource.setValidationQuery("SELECT 1 FROM DUAL"); } 
  basicDataSource.setMaxTotal(20);
  basicDataSource.setMaxIdle(20); 
  basicDataSource.setDefaultAutoCommit(false);
}
Mr. Polywhirl
  • 42,981
  • 12
  • 84
  • 132
  • What was the case of application got hang/unresponsive? was it a bug? – Ori Marko Jul 24 '19 at 10:25
  • No it was not a code bug. Let's assume there were maxActive connection limit = 20 and one request needs 2 connection. Then we hit 11 requests(means connections needed = 22) in parallel which lead to server unresponsive. – Sachin Kumar Jul 25 '19 at 06:55
  • Show your configuration – Ori Marko Jul 25 '19 at 09:51
  • `final BasicDataSource basicDataSource = new BasicDataSource();` `basicDataSource.setUrl(url);` `basicDataSource.setUsername(user);` `basicDataSource.setPassword(password);` `basicDataSource.setDriverClassName(driver);` `if (driver.contains("oracle")) {` `basicDataSource.setValidationQuery("SELECT 1 FROM DUAL");` `}` `basicDataSource.setMaxTotal(20);` `basicDataSource.setMaxIdle(20);` `basicDataSource.setDefaultAutoCommit(false);` – Sachin Kumar Jul 26 '19 at 08:21

1 Answers1

0

Motivations to limit the number of connections in a db-Pool

  • The maximum number of connections clients might create to a DBMS normally is limited. By limiting the number of connections a node can use at the same time, you can calculate the hard limit and avoid meeting it.
  • if your application has a connection leak, this will hopefully lead on a single node to an error, not on the complete cluster, so you can handle it earlier, not when the DBMS stops working because all possible connections a dangling.
aschoerk
  • 3,333
  • 2
  • 15
  • 29