Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Optimal number of connections in connection pool

Currently we are using 4 cpu windows box with 8gb RAM with MySQL 5.x installed on same box. We are using Weblogic application server for our application. We are targeting for 200 concurrent users for our application (Obviously not for same module/screen). So what is optimal number of connections should we configured in connection pool (min and max number) (We are using weblogic AS' connection pooling mechanism) ?

like image 718
Silent Warrior Avatar asked Jul 30 '09 17:07

Silent Warrior


People also ask

How many connection pools should I have?

The number of connections in the connection pool should be equal the number of the exec threads configured in WebLogic. The rationale is very simple: If the number of the connections is less than the number of threads, some of the thread maybe waiting for a connection thus making the connection pool a bottleneck.

How many connections can you have in a pool?

A pool contains two types of connections: Active connection: In use by the application. Idle connection: Available for use by the application.

What specifies the number of connections in a connection pool?

Maximum connections. Specifies the maximum number of physical connections that you can create in this pool. These are the physical connections to the backend resource.


4 Answers

Did you really mean 200 concurrent users or just 200 logged in users? In most cases, a browser user is not going to be able to do more than 1 page request per second. So, 200 users translates into 200 transactions per second. That is a pretty high number for most applications.

Regardless, as an example, let's go with 200 transactions per second. Say each front end (browser) tx takes 0.5 seconds to complete and of the 0.5 seconds, 0.25 are spent in the database. So, you would need 0.5 * 200, or 100 connections in the WebLogic thead pool and 0.25 * 200 = 50 connections in the DB connection pool.

To be safe, I would set the max thread pool sizes to at least 25% larger than you expect to allow for spikes in load. The minimums can be a small fraction of the max, but the tradeoff is that it could take longer for some users because a new connection would have to be created. In this case, 50 - 100 connections is not that many for a DB so that's probably a good starting number.

Note, that to figure out what your average transaction response times are, along with your average DB query time, you are going to have to do a performance test because your times at load are probably not going to be the times you see with a single user.

like image 57
AngerClown Avatar answered Oct 06 '22 00:10

AngerClown


There is a very simple answer to this question:

The number of connections in the connection pool should be equal the number of the exec threads configured in WebLogic.

The rationale is very simple: If the number of the connections is less than the number of threads, some of the thread maybe waiting for a connection thus making the connection pool a bottleneck. So, it should be equal at least the number the exec threads (thread pool size).

like image 44
Slava Imeshev Avatar answered Oct 05 '22 22:10

Slava Imeshev


Sizing a connection pool is not a trivial thing to do. You basically need:

  • metrics to investigate the connection usage
  • failover mechanisms for when there is no connection available

FlexyPool aims to aid you in figuring out the right connection pool size.

like image 22
Vlad Mihalcea Avatar answered Oct 05 '22 22:10

Vlad Mihalcea


You should profile the different expected workflows to find out. Ideally, your connection pool will also dynamically adjust the number of live connections based on recent usage, as it's pretty common for load to be a function of the current time of day in your target geographical area.

Start with a small number and try to reach a reasonable number of concurrent users, then crank it up. I think it's likely that you'll find that your connection pooling mechanism is not nearly as instrumental in your scalability as the rest of the software.

like image 30
Greg D Avatar answered Oct 05 '22 23:10

Greg D