Hi all, I am interested to learn more about connection pooling in rails. Is there any good articles about this? I want to know specifically how is connection pooling in rails works. Does rails open one connection to the database for every user that is connected or does every user share the same database connection? Does different app server handles connection pooling differently [i.e passenger, unicorn, mongrel, thin] ? Or does app server doesn''t really care about this? Thank you very much in advance for your help and insights. Kind regards, Joshua. -- http://twitter.com/scrum8 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Sun, Sep 5, 2010 at 8:57 AM, Joshua Partogi <joshua.partogi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi all, > > I am interested to learn more about connection pooling in rails. Is there > any good articles about this? I want to know specifically how is connection > pooling in rails works. Does rails open one connection to the database for > every user that is connected or does every user share the same database > connection? Does different app server handles connection pooling differently > [i.e passenger, unicorn, mongrel, thin] ? Or does app server doesn''t really > care about this? > > Thank you very much in advance for your help and insights.Hi Joshua, Here are some facts about connection pooling that should answer your questions: * Connection pooling is handled inside of ActiveRecord, so all application servers should behave basically the same. * The database connection pool starts out empty and creates connections over time according to demand. The maximum size of this pool defaults to 5 and is configured in database.yml. * Requests and users share connections from this pool. A request checks out a connection the first time it needs to access the database and then checks the connection back in at the end of the request. * If you use Rails.threadsafe! mode, then multiple threads might be accessing multiple connections at the same time, so depending on the request load you might have multiple threads contending for a few connections. /Nick -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi Nick, Thank you for the response. You mentioned that database connection pool is created according to demand. What does that mean? Does it mean if there are more users it will open more connection thus create more connection pool? Thanks heaps in advance. Kind regards, Joshua On Sep 6, 4:32 am, Nick Sieger <nicksie...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sun, Sep 5, 2010 at 8:57 AM, Joshua Partogi <joshua.part...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hi all, > > > I am interested to learn more about connection pooling in rails. Is there > > any good articles about this? I want to know specifically how is connection > > pooling in rails works. Does rails open one connection to the database for > > every user that is connected or does every user share the same database > > connection? Does different app server handles connection pooling differently > > [i.e passenger, unicorn, mongrel, thin] ? Or does app server doesn''t really > > care about this? > > > Thank you very much in advance for your help and insights. > > Hi Joshua, > > Here are some facts about connection pooling that should answer your questions: > > * Connection pooling is handled inside of ActiveRecord, so all > application servers should behave basically the same. > > * The database connection pool starts out empty and creates > connections over time according to demand. The maximum size of this > pool defaults to 5 and is configured in database.yml. > > * Requests and users share connections from this pool. A request > checks out a connection the first time it needs to access the database > and then checks the connection back in at the end of the request. > > * If you use Rails.threadsafe! mode, then multiple threads might be > accessing multiple connections at the same time, so depending on the > request load you might have multiple threads contending for a few > connections. > > /Nick-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Wed, Sep 15, 2010 at 5:08 PM, Joshua Partogi <joshua.partogi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi Nick, > > Thank you for the response. You mentioned that database connection > pool is created according to demand. What does that mean? Does it mean > if there are more users it will open more connection thus create more > connection pool?Yes. What I meant to say is that the pool starts out empty and only grows as connections are needed up to the maximum pool size. If you are running non-thread-safe Rails with a request mutex, chances are that you won''t create more than one connection. /Nick> > Thanks heaps in advance. > > Kind regards, > Joshua > > On Sep 6, 4:32 am, Nick Sieger <nicksie...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> On Sun, Sep 5, 2010 at 8:57 AM, Joshua Partogi <joshua.part...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > Hi all, >> >> > I am interested to learn more about connection pooling in rails. Is there >> > any good articles about this? I want to know specifically how is connection >> > pooling in rails works. Does rails open one connection to the database for >> > every user that is connected or does every user share the same database >> > connection? Does different app server handles connection pooling differently >> > [i.e passenger, unicorn, mongrel, thin] ? Or does app server doesn''t really >> > care about this? >> >> > Thank you very much in advance for your help and insights. >> >> Hi Joshua, >> >> Here are some facts about connection pooling that should answer your questions: >> >> * Connection pooling is handled inside of ActiveRecord, so all >> application servers should behave basically the same. >> >> * The database connection pool starts out empty and creates >> connections over time according to demand. The maximum size of this >> pool defaults to 5 and is configured in database.yml. >> >> * Requests and users share connections from this pool. A request >> checks out a connection the first time it needs to access the database >> and then checks the connection back in at the end of the request. >> >> * If you use Rails.threadsafe! mode, then multiple threads might be >> accessing multiple connections at the same time, so depending on the >> request load you might have multiple threads contending for a few >> connections. >> >> /Nick > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks Nick. You have been really helpful. I am just trying to figure out how this is different to connection pooling in the Java land. =) Cheers, Joshua. On Sep 16, 11:12 pm, Nick Sieger <nicksie...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Wed, Sep 15, 2010 at 5:08 PM, Joshua Partogi > > <joshua.part...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hi Nick, > > > Thank you for the response. You mentioned that database connection > > pool is created according to demand. What does that mean? Does it mean > > if there are more users it will open more connection thus create more > > connection pool? > > Yes. What I meant to say is that the pool starts out empty and only > grows as connections are needed up to the maximum pool size. If you > are running non-thread-safe Rails with a request mutex, chances are > that you won''t create more than one connection. > > /Nick > > > > > > > Thanks heaps in advance. > > > Kind regards, > > Joshua > > > On Sep 6, 4:32 am, Nick Sieger <nicksie...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> On Sun, Sep 5, 2010 at 8:57 AM, Joshua Partogi <joshua.part...@gmail.com> wrote: > >> > Hi all, > > >> > I am interested to learn more about connection pooling in rails. Is there > >> > any good articles about this? I want to know specifically how is connection > >> > pooling in rails works. Does rails open one connection to the database for > >> > every user that is connected or does every user share the same database > >> > connection? Does different app server handles connection pooling differently > >> > [i.e passenger, unicorn, mongrel, thin] ? Or does app server doesn''t really > >> > care about this? > > >> > Thank you very much in advance for your help and insights. > > >> Hi Joshua, > > >> Here are some facts about connection pooling that should answer your questions: > > >> * Connection pooling is handled inside of ActiveRecord, so all > >> application servers should behave basically the same. > > >> * The database connection pool starts out empty and creates > >> connections over time according to demand. The maximum size of this > >> pool defaults to 5 and is configured in database.yml. > > >> * Requests and users share connections from this pool. A request > >> checks out a connection the first time it needs to access the database > >> and then checks the connection back in at the end of the request. > > >> * If you use Rails.threadsafe! mode, then multiple threads might be > >> accessing multiple connections at the same time, so depending on the > >> request load you might have multiple threads contending for a few > >> connections. > > >> /Nick > > > -- > > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Joshua Partogi wrote:> Thanks Nick. You have been really helpful. I am just trying to figure > out how this is different to connection pooling in the Java land. =) > > Cheers, > Joshua.Hi Joshua/Nick, I have one question related to multiple database session in ruby on rails. Can I have specific database session for every user session. So that multiple users can connect to multiple databases dynamically. Can I use connection pooling for the same? Thanks Nitin. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.