establish connection creates new connection pool on each request
24 views
Skip to first unread message
vaibhav paliwal
unread,
Dec 21, 2017, 9:26:25 AM12/21/17
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Ruby on Rails: Talk
Hi,
In our rails application we need to establish connection to database based on the client id in the URL. Currently we are using establish_connection but it looks like it creates new connection pool each time and executes some queries to get schema information about DB. Is there a way to cache connection pool ? I am also curious why did Active Record decided not to cache the connection pools based on configuration ? I am not sure if its a great idea to subclass ConnectionHandler and roll my own connection pool caching something like this any opinions ?
Thanks
Walter Lee Davis
unread,
Dec 22, 2017, 10:03:13 AM12/22/17
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to rubyonra...@googlegroups.com
Are you seeing this in development or production? I would expect this behavior in development, but never in production. In my experience, connection pools are established and maintained for the run-time of the application. Naturally, if you are deployed in an auto-scaling environment, each instance of your app will get its own pool(s), but that's to be expected.
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Ruby on Rails: Talk
Thanks for your reply. I am seeing this in production. I thought connection pool will be maintained for the run time of application too but looking at the establish_connection source code it looks like it clears the existing pools and creates a new connection pool. I thought it would be checking if there is already a connection pool existing for the spec and if not then create the connection pool. This makes me wonder if its a good idea to cache connection pool in an ivar in my application when Active Record decided not to do it.