In #1335 Connection pool creating a new connection for every http request 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 Connection pool creating a new connection for every http request 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)