user811433
user811433

Reputation: 4149

What is the ideal maxActive value for tomcat datasource for a high concurrency application?

What is the ideal maxActive value for tomcat datasource for a high concurrency application? Especially in the production environment. My application's DB is SQL Server.

When sending multiple requests I currently see the below error:

java.util.concurrent.ExecutionException: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot get a connection, pool error Timeout waiting for idle object 

Setting maxActive to -1 resolves my problem, but is that an ideal value for a production environment?

Upvotes: 1

Views: 2571

Answers (1)

Stefan Haberl
Stefan Haberl

Reputation: 10559

I guess, you really have to benchmark.

We load-tested our Tomcat and were surprised that throughput peeked at around a max. of 10 concurrent connections, when we initially thought the value of maxActive should be much higher. (Disclaimer: This is an inhouse app, where the DB is running on a relatively small box. The correct value might be considerably higher if you're running a high concurrency app on a power horse).

There's good background information about pool sizing on HikariCP's wiki pages, which should also apply to Apache DBCP shipped with Tomcat:

https://github.com/brettwooldridge/HikariCP/wiki/About-Pool-Sizing

It basically says you should set the number of concurrent connections to twice the number of CPU cores available to your DB instance. But again, I would load-test your app to confirm that number.

After you have found the optimal pool size, rather consider increasing the maxWait property of the pool to avoid the CannotGetJdbcConnectionException exception you are mentioning. See the DBCP's JavaDoc for details:

http://commons.apache.org/proper/commons-dbcp/api-1.4/org/apache/commons/dbcp/BasicDataSource.html#maxWait

Upvotes: 1

Related Questions