Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

[PATCH] Do not reload ActiveRecord connections in development mode

#4929

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)

Reported by Edgars Beigarts · June 22nd, 2010 @ 10:21 AM

State: resolved
Milestone: none
Assigned to: José Valim José Valim
Importance: none

Activity

  1. Edgars Beigarts
    Edgars Beigarts

    I can also confirm that with Oracle it reuses the same connection and doesn't create any new connections to database.

    June 22nd, 2010 @ 10:24 AM

  2. Edgars Beigarts
    Edgars Beigarts
    • Assigned user changed from Pratik to José Valim

    June 22nd, 2010 @ 05:56 PM

  3. Repository