This project is archived and is in readonly mode.
[PATCH] Do not reload ActiveRecord connections in development mode
Reported by Edgars Beigarts | June 22nd, 2010 @ 10:21 AM
In #1335 it was changed that all database adapters
requires connection reloading in development mode and the real
problem wasn't solved there.
The real problem is in clear_reloadable_connections!, it always
resets @connnections to [] on each request without checking if
connection needs to be reloaded.
My patch will not reset @connections for connections that
doesn't need to be reloaded.
I changed also that all adapters except SQLite needs to be reloaded
as it was before #1335 changes (see http://github.com/rails/rails/commit/6d37c638
).
So if database is running on localhost this will save at least
1ms (MySQL), 8ms (PostgreSQL) and
182ms (Oracle) for each request in development
mode.
If database is located somewhere in WAN it can take up to
1s for Oracle to reestablish a connection on each
request.
So development mode gets very slow if database is not running
locally.
Benchmarks with databases running locally:
require "benchmark"
require "active_record/connection_adapters/mysql_adapter"
puts Benchmark.measure { ActiveRecord::Base.mysql_connection :database => "development", :username => "root" }
# => 0.000000 0.000000 0.000000 ( 0.001100)
require "active_record/connection_adapters/postgresql_adapter"
puts Benchmark.measure { ActiveRecord::Base.postgresql_connection :database => "postgres", :username => "be" }
# => 0.010000 0.000000 0.010000 ( 0.008982)
require "active_record/connection_adapters/oracle_enhanced_adapter"
puts Benchmark.measure { ActiveRecord::Base.oracle_enhanced_connection :database => "xe", :username => "hr", :password => "hr" }
# => 0.000000 0.010000 0.010000 ( 0.182331)
Comments and changes to this ticket
-
Edgars Beigarts June 22nd, 2010 @ 10:24 AM
I can also confirm that with Oracle it reuses the same connection and doesn't create any new connections to database.
-
Edgars Beigarts June 22nd, 2010 @ 05:56 PM
- Assigned user changed from Pratik to José Valim
-
Repository June 22nd, 2010 @ 08:54 PM
- State changed from new to resolved
(from [62c4e4d3856b38ee9869f4ad6342e712788c8635]) Fix connection reloading in development mode. [#4929 state:resolved]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/62c4e4d3856b38ee9869f4ad6342e7...
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
Attachments
Referenced by
- 4929 [PATCH] Do not reload ActiveRecord connections in development mode (from [62c4e4d3856b38ee9869f4ad6342e712788c8635]) Fix con...