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

**URL:** <https://www.ruby-forum.com/t/how-many-connection-pool-should-we-have-for-internet-facing-apps/187775>\
**Category:** Rails\
**Created:** [April 29, 2010, 2:59am UTC](https://www.ruby-forum.com/t/how-many-connection-pool-should-we-have-for-internet-facing-apps/187775 "2010-04-29T02:59:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![builtbysimple](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/aca169/32.png) [@builtbysimple](https://www.ruby-forum.com/u/builtbysimple)\
**Post date:** [April 29, 2010, 2:59am UTC](https://www.ruby-forum.com/t/how-many-connection-pool-should-we-have-for-internet-facing-apps/187775/1 "2010-04-29T02:59:07Z")

</div>

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

–  
[http://twitter.com/scrum8](http://twitter.com/scrum8)

---

<div class="post-metadata">

**Author:** ![builtbysimple](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/aca169/32.png) [@builtbysimple](https://www.ruby-forum.com/u/builtbysimple)\
**Post date:** [April 29, 2010, 10:17am UTC](https://www.ruby-forum.com/t/how-many-connection-pool-should-we-have-for-internet-facing-apps/187775/2 "2010-04-29T10:17:33Z")

</div>

On Apr 29, 1:57 am, Joshua P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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)

Fred

---

<div class="post-metadata">

**Author:** ![builtbysimple](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/aca169/32.png) [@builtbysimple](https://www.ruby-forum.com/u/builtbysimple)\
**Post date:** [April 30, 2010, 7:54pm UTC](https://www.ruby-forum.com/t/how-many-connection-pool-should-we-have-for-internet-facing-apps/187775/3 "2010-04-30T19:54:53Z")

</div>

Frederick C. wrote:

> > 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?

---

<div class="post-metadata">

**Author:** ![builtbysimple](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/aca169/32.png) [@builtbysimple](https://www.ruby-forum.com/u/builtbysimple)\
**Post date:** [May 1, 2010, 1:08pm UTC](https://www.ruby-forum.com/t/how-many-connection-pool-should-we-have-for-internet-facing-apps/187775/4 "2010-05-01T13:08:25Z")

</div>

On Apr 30, 6:52 pm, “Joe S.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > users that will be accessing the app, how many connection pool should  
> > > 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
