This project is archived and is in readonly mode.
Connection pool creating a new connection for every http request
Reported by thrillhouse | November 6th, 2008 @ 01:11 AM
Every http request appears to be establishing a new database connection rather than checking connections in and out of the pool.
Each time the application reaches the checkout method in ActiveRecord::ConnectionAdapters::ConnectionPool, both @checked_out.size and @connections.size are always zero, despite there being numerous open connections. This results in the checkout of a new connection for every http request. Although the newly checked out connection is being correctly appended to the list of open connections via the checkout_new_connection method, the @connections list appears to have been emptied by the time a new request is made.
I have been able to reproduce the problem with a fresh rails app in the following environments
- 2 Windows machines running edge rails with ruby 1.8.6 patch level 111
- 1 Windows machine running edge rails with ruby 1.8.5 (2006-08-25)
- 1 Mac OSX machine running edge rails with ruby 1.8.6 patch level 111
Against these environments I have tested with both Oracle and MySQL. The issue is not quite as evident using MySQL because a show processlist reveals that MySQL appears to 'clean up' active connections that are not being used. Thus, with one user hitting the app, the number of connections to MySQL doesn't get beyond roughly 10 before they are 'cleaned up'. Oracle is a different story. The number of connections to the database quickly spirals out of control (as seen via SELECT * FROM v$session;). In fact if not for Oracle we would not have noticed this happening.
Strangely enough, a Redhat machine running edge rails with ruby 1.8.5 (2006-08-25) [x86_64-linux] against Oracle does not reproduce the same error.
Comments and changes to this ticket
-
Zyclops November 6th, 2008 @ 10:39 PM
I can confirm that this is the case under OSX with MySQL under ruby 1.8.6. Too me it looks like the variable that contains a list of the connections isn't maintaining state between requests.
-
Pratik November 6th, 2008 @ 10:56 PM
- Milestone cleared.
-
Zyclops November 6th, 2008 @ 11:04 PM
This only happens in development mode (thanks lifo) and is to do with class reloading.
In production it works fine.
In development mode it is an issue since under oracle it causes hundreds of connections to rack up and eventually locks up the database (MySQL is nice since it does some housekeeping and cleans up the connections).
-
Pratik November 6th, 2008 @ 11:34 PM
- Assigned user set to Pratik
-
Repository November 7th, 2008 @ 11:35 PM
- State changed from new to resolved
(from [d20955f889223b6035dbc7d61acba9091bf7b7ed]) Don't leave open dangling connections in development mode. [#1335 state:resolved] http://github.com/rails/rails/co...
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Tags
Referenced by
- 1335 Connection pool creating a new connection for every http request (from [d20955f889223b6035dbc7d61acba9091bf7b7ed]) Don't l...
- 4929 [PATCH] Do not reload ActiveRecord connections in development mode In #1335 it was changed that all database adapters requir...
- 4929 [PATCH] Do not reload ActiveRecord connections in development mode My patch will not reset @connections for connections that...