This project is archived and is in readonly mode.

#4929 ✓resolved
Edgars Beigarts

[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 ).

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

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=""></a>

People watching this ticket


Referenced by