How many connection pool should we have for internet facing apps?

Hi all,

This is a rather basic question about connection pooling in ruby on rails. In rails we can define the connection pool in database.yml. I assume it is quite safe to hardcode this value for intranet application since we would know how many users that will be using the apps. But for an internet facing apps where we don't know how many users that will be accessing the app, how many connection pool should we provide ? Can anyone share their experience on this to enlighten me?

Thank you very much in advance for the insights.

Kind regards, Joshua

Hi all,

This is a rather basic question about connection pooling in ruby on rails. In rails we can define the connection pool in database.yml. I assume it is quite safe to hardcode this value for intranet application since we would know how many users that will be using the apps. But for an internet facing apps where we don't know how many users that will be accessing the app, how many connection pool should we provide ? Can anyone share their experience on this to enlighten me?

Connection pool size isn't really related to number of users. It doesn't really make much difference without a multithreaded setup (and your default 'normal' ruby + passenger or mongrel isn't one of those)

Fred

Frederick Cheung wrote:

Hi all,

This is a rather basic question about connection pooling in ruby on rails. In rails we can define the connection pool in database.yml. I assume it is quite safe to hardcode this value for intranet application since we would know how many users that will be using the apps. But for an internet facing apps where we don't know how many users that will be accessing the app, how many connection pool should we provide ? Can anyone share their experience on this to enlighten me?

Connection pool size isn't really related to number of users. It doesn't really make much difference without a multithreaded setup (and your default 'normal' ruby + passenger or mongrel isn't one of those)

Fair enough, in the default state with passenger, you have a multi-process setup, and since each process is independent, they don't know of each other, and thus the value for connection in the database.yml file is more or less meaningless. (It is good to be explicit in explainging why this is the case).

Nevertheless, the database itself may have a limited connection pool, rather than using the standard UNIX model of fork a new process on connection, or othewrwise put a user-configurable constraint on number of active connections. (I undertsand that MySQL often has such a limit.) Any guidance for the original poster on how best to deal with that?

Frederick Cheung wrote: >> Hi all,

>> This is a rather basic question about connection pooling in ruby on >> rails. In rails we can define the connection pool in database.yml. I >> assume it is quite safe to hardcode this value for intranet >> application since we would know how many users that will be using the >> apps. But for an internet facing apps where we don't know how many >> users that will be accessing the app, how many connection pool should >> we provide ? Can anyone share their experience on this to enlighten >> me?

>Connection pool size isn't really related to number of users. It >doesn't really make much difference without a multithreaded setup (and >your default 'normal' ruby + passenger or mongrel isn't one of those)

Fair enough, in the default state with passenger, you have a multi-process setup, and since each process is independent, they don't know of each other, and thus the value for connection in the database.yml file is more or less meaningless. (It is good to be explicit in explainging why this is the case).

Nevertheless, the database itself may have a limited connection pool, rather than using the standard UNIX model of fork a new process on connection, or othewrwise put a user-configurable constraint on number of active connections. (I undertsand that MySQL often has such a limit.) Any guidance for the original poster on how best to deal with that?

Well if your database has a limit on the number of connections, ensure that it's greater than the number of mongrels/passenger instances (and if you're going to actually be using the connection pooling stuff i suppose you'd want to make it greater than the sum of the size of the connection pool across application instances). I seem to remember the default limit on mysql is 100, but it can go way higher than that (and if you are going to have several hundred mongrels you can probably afford a big beefy database server too)

Fred