Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Commits on Jan 13, 2015
  1. Tsuneo Yoshioka

    ActiveRecord: On reconnection failure, release only failed connetion.

    yoshiokatsuneo authored
    On reconnection failure, all the connection was released.
    But, it is better to release only failed connection.
    This patch changes not to release all the connection but release
    only failed connection.
Commits on Jan 9, 2015
  1. Tsuneo Yoshioka

    ActiveRecord: release connection on reconnect failure.

    yoshiokatsuneo authored
    When trying to checkout connection from connection pool,
    checkout()(and checkout_and_verify) verify whether the connection
    is active or not.
    And, if the connection is not active, connection adapters try to
    reconnect to server.  And, if database is down at this moment,
    reconnect fails and exception is raised.
    (Ex: Mysql2::Error: Can't connect to local MySQL server through socket xxx)
    
    But, ConnectionPool does not catch the exception, but leaks current
    disconnected connection to @connection.
    So, if database's temporary down happens several times and exceeds
    the number of connection pool(5 by default), activerecord will be
    no more available, even if database server is already recovered.
    
    This patch fix it by catching exception and releasing connection.
Commits on Jan 4, 2015
  1. Rafael Mendonça França
Commits on Jan 2, 2015
  1. Rafael Mendonça França

    Merge pull request #18080 from korbin/fix_reaping_frequency_configura…

    rafaelfranca authored
    …tion
    
    Fix issue with reaping_frequency type.
Commits on Dec 23, 2014
  1. Matt Jones

    Fix connection leak when a thread checks in additional connections.

    al2o3cr authored
    The code in `ConnectionPool#release` assumed that a single thread only
    ever holds a single connection, and thus that releasing a connection
    only requires the owning thread_id.
    
    There is a trivial counterexample to this assumption: code that checks
    out additional connections from the pool in the same thread. For
    instance:
    
        connection_1 = ActiveRecord::Base.connection
        connection_2 = ActiveRecord::Base.connection_pool.checkout
        ActiveRecord::Base.connection_pool.checkin(connection_2)
        connection_3 = ActiveRecord::Base.connection
    
    At this point, connection_1 has been removed from the
    `@reserved_connections` hash, causing a NEW connection to be returned as
    connection_3 and the loss of any tracking info on connection_1. As long
    as the thread in this example lives, connection_1 will be inaccessible
    and un-reapable. If this block of code runs more times than the size of
    the connection pool in a single thread, every subsequent connection
    attempt will timeout, as all of the available connections have been
    leaked.
    
    Reverts parts of 9e457a8 and
    essentially all of 4367d2f
Commits on Dec 18, 2014
  1. korbin

    fix issue with reaping_frequency type

    korbin authored
    When using DATABASE_URL to configure ActiveRecord, :reaping_frequency
    does not get converted from a string to a numeric value. This value is
    eventually passed to 'sleep' and must be numeric to avoid exceptions.
    
    This commit converts :reaping_frequency to a float when present.
Commits on Dec 8, 2014
  1. Neeraj Singh

    minor sentences fixes

    neerajdotname authored
Commits on Nov 29, 2014
  1. Erik Michaels-Ober
Commits on Oct 29, 2014
  1. Xavier Noria

    edit pass over all warnings

    fxn authored
    This patch uniformizes warning messages. I used the most common style
    already present in the code base:
    
    * Capitalize the first word.
    
    * End the message with a full stop.
    
    * "Rails 5" instead of "Rails 5.0".
    
    * Backticks for method names and inline code.
    
    Also, converted a few long strings into the new heredoc convention.
Commits on Oct 28, 2014
  1. Xavier Noria

    let's warn with heredocs

    fxn authored
    The current style for warning messages without newlines uses
    concatenation of string literals with manual trailing spaces
    where needed.
    
    Heredocs have better readability, and with `squish` we can still
    produce a single line.
    
    This is a similar use case to the one that motivated defining
    `strip_heredoc`, heredocs are super clean.
Commits on Oct 26, 2014
  1. Rafael Mendonça França

    Prefix internal method with _

    rafaelfranca authored
    This will avoid naming clash with user defined methods
Commits on Sep 28, 2014
  1. pete higgins

    Reduce allocations when running AR callbacks.

    phiggins authored
    Inspired by @tenderlove's work in
    c363fff, this reduces the number of
    strings allocated when running callbacks for ActiveRecord instances. I
    measured that using this script:
    
    ```
    require 'objspace'
    require 'active_record'
    require 'allocation_tracer'
    
    ActiveRecord::Base.establish_connection adapter: "sqlite3",
                                            database: ":memory:"
    
    ActiveRecord::Base.connection.instance_eval do
      create_table(:articles) { |t| t.string :name }
    end
    
    class Article < ActiveRecord::Base; end
    a = Article.create name: "foo"
    a = Article.find a.id
    
    N = 10
    result = ObjectSpace::AllocationTracer.trace do
      N.times { Article.find a.id }
    end
    
    result.sort.each do |k,v|
      p k => v
    end
    puts "total: #{result.values.map(&:first).inject(:+)}"
    ```
    
    When I run this against master and this branch I get this output:
    
    ```
    pete@balloon:~/projects/rails/activerecord$ git checkout master
    M Gemfile
    Switched to branch 'master'
    pete@balloon:~/projects/rails/activerecord$ bundle exec ruby benchmark_allocation_with_callback_send.rb > allocations_before
    pete@balloon:~/projects/rails/activerecord$ git checkout remove-dynamic-send-on-built-in-callbacks
    M Gemfile
    Switched to branch 'remove-dynamic-send-on-built-in-callbacks'
    pete@balloon:~/projects/rails/activerecord$ bundle exec ruby benchmark_allocation_with_callback_send.rb > allocations_after
    pete@balloon:~/projects/rails/activerecord$ diff allocations_before allocations_after
    39d38
    <
    {["/home/pete/projects/rails/activesupport/lib/active_support/callbacks.rb",
    81]=>[40, 0, 0, 0, 0, 0]}
    42c41
    < total: 630
    ---
    > total: 590
    
    ```
    
    In addition to this, there are two micro-optimizations present:
    
    * Using `block.call if block` vs `yield if block_given?` when the block was being captured already.
    
    ```
    pete@balloon:~/projects$ cat benchmark_block_call_vs_yield.rb
    require 'benchmark/ips'
    
    def block_capture_with_yield &block
      yield if block_given?
    end
    
    def block_capture_with_call &block
      block.call if block
    end
    
    def no_block_capture
      yield if block_given?
    end
    
    Benchmark.ips do |b|
      b.report("block_capture_with_yield") { block_capture_with_yield }
      b.report("block_capture_with_call") { block_capture_with_call }
      b.report("no_block_capture") { no_block_capture }
    end
    pete@balloon:~/projects$ ruby benchmark_block_call_vs_yield.rb
    Calculating -------------------------------------
    block_capture_with_yield
                            124979 i/100ms
    block_capture_with_call
                            138340 i/100ms
        no_block_capture    136827 i/100ms
    -------------------------------------------------
    block_capture_with_yield
                          5703108.9 (±2.4%) i/s -   28495212 in   4.999368s
    block_capture_with_call
                          6840730.5 (±3.6%) i/s -   34169980 in   5.002649s
        no_block_capture  5821141.4 (±2.8%) i/s -   29144151 in   5.010580s
    ```
    
    * Defining and calling methods instead of using send.
    
    ```
    pete@balloon:~/projects$ cat benchmark_method_call_vs_send.rb
    require 'benchmark/ips'
    
    class Foo
      def tacos
        nil
      end
    end
    
    my_foo = Foo.new
    
    Benchmark.ips do |b|
      b.report('send') { my_foo.send('tacos') }
      b.report('call') { my_foo.tacos }
    end
    pete@balloon:~/projects$ ruby benchmark_method_call_vs_send.rb
    Calculating -------------------------------------
                    send     97736 i/100ms
                    call    151142 i/100ms
    -------------------------------------------------
                    send  2683730.3 (±2.8%) i/s -   13487568 in   5.029763s
                    call  8005963.9 (±2.7%) i/s -   40052630 in   5.006604s
    ```
    
    The result of this is making typical ActiveRecord operations slightly faster:
    
    https://gist.github.com/phiggins/e46e51dcc7edb45b5f98
Commits on Sep 23, 2014
  1. Simon Eskildsen

    ar/connection_pool: honor overriden rack.test in middleware

    Sirupsen authored
    Honoring an overidden `rack.test` allows testing closed connection between
    multiple requests. This is useful if you're working on database resiliency, to
    ensure the connection is in the expected state from one request to another on
    the same worker.
Commits on Aug 19, 2014
  1. Rafael Mendonça França

    Merge pull request #16542 from seamusabshere/numerify-pool-checkout-t…

    rafaelfranca authored
    …imeout-from-urls-4-1-stable
    
    Make sure :checkout_timeout and :dead_connection_timeout are numbers
    Conflicts:
    	activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
Commits on Jul 31, 2014
  1. Jack Danger Canty

    Clarify how the ConnectionHandler works

    JackDanger authored
    This makes the implicit description of how connection pooling works a
    little more explicit. It converts the examples of a model hierarchy into
    actual Ruby code and demonstrates how the key structure of the
    database.yml relates to the `establish_connection` method.
Commits on Jun 23, 2014
  1. Mindaugas Mozūras
Commits on Mar 18, 2014
  1. Matthew Draper

    Reap connections based on owning-thread death

    matthewd authored
    .. not a general timeout.
    
    Now, if a thread checks out a connection then dies, we can immediately
    recover that connection and re-use it.
    
    This should alleviate the pool exhaustion discussed in #12867. More
    importantly, it entirely avoids the potential issues of the reaper
    attempting to check whether connections are still active: as long as the
    owning thread is alive, the connection is its business alone.
    
    As a no-op reap is now trivial (only entails checking a thread status
    per connection), we can also perform one in-line any time we decide to
    sleep for a connection.
Commits on Feb 22, 2014
  1. Jeremy Kemper

    Distinguish ConnectionNotEstablished messages: no conn pool for the c…

    jeremy authored
    …lass, or no conn available from the pool
Commits on Feb 9, 2014
  1. Kevin Casey
Commits on Dec 3, 2013
  1. Lauro Caetano
Commits on Jul 22, 2013
  1. Vipul A M

    rescue from all exceptions in `ConnectionManagement#call`

    vipulnsward authored
    Fixes #11497
    
    As `ActiveRecord::ConnectionAdapters::ConnectionManagement` middleware does not rescue from Exception (but only from StandardError),
    the Connection Pool quickly runs out of connections when multiple erroneous Requests come in right after each other.
    
    Recueing from all exceptions and not just StandardError, fixes this behaviour.
Commits on Jul 2, 2013
  1. Francesco Rodríguez
Commits on Apr 24, 2013
  1. Ivan Kataitsev
Commits on Mar 20, 2013
  1. Aaron Patterson
  2. Aaron Patterson

    Revert "default the reaping frequency to 10 seconds"

    tenderlove authored
    mysql can't handle a parallel thread pinging the connection, so we can
    get wrong results or segvs
    
    This reverts commit 7cc588b.
Commits on Mar 11, 2013
  1. Aaron Patterson
Commits on Feb 18, 2013
  1. Akira Matsuda
Commits on Jan 24, 2013
  1. Akira Matsuda

    Default dead_connection_timeout to 5

    amatsuda authored
    or the ConnectionPool silently fails to close connections inside the Thread
Commits on Jan 19, 2013
  1. David Wang

    fix anonymous class issue

    dahakawang authored
Commits on Jan 6, 2013
  1. Akira Matsuda

    These are already required through AS/rails

    amatsuda authored
    * dependencies/autoload
    * concern
    * deprecation
Commits on Dec 14, 2012
  1. thedarkone

    Replace some global Hash usages with the new thread safe cache.

    thedarkone authored
    Summary of the changes:
     * Add thread_safe gem.
     * Use thread safe cache for digestor caching.
     * Replace manual synchronization with ThreadSafe::Cache in Relation::Delegation.
     * Replace @attribute_method_matchers_cache Hash with ThreadSafe::Cache.
     * Use TS::Cache to avoid the synchronisation overhead on listener retrieval.
     * Replace synchronisation with TS::Cache usage.
     * Use a preallocated array for performance/memory reasons.
     * Update the controllers cache to the new AS::Dependencies::ClassCache API.
       The original @controllers cache no longer makes much sense after @tenderlove's
       changes in 7b6bfe8 and f345e23.
     * Use TS::Cache in the connection pool to avoid locking overhead.
     * Use TS::Cache in ConnectionHandler.
Commits on Nov 30, 2012
  1. Jon Leighton

    Fix memory leak in development mode

    jonleighton authored
    Keying these hashes by klass causes reloadable classes to never get
    freed. Thanks to @thedarkone for pointing this out in
    the comments on 221571b.
    
    This doesn't seem to make a massive difference to performance.
    
    Benchmark
    ---------
    
    require 'active_record'
    require 'benchmark/ips'
    
    class Post < ActiveRecord::Base
      establish_connection adapter: 'sqlite3', database: ':memory:'
    end
    
    GC.disable
    
    Benchmark.ips(20) do |r|
      r.report { Post.connection }
    end
    
    Before
    ------
    
    Calculating -------------------------------------
                              5632 i/100ms
    -------------------------------------------------
                           218671.0 (±1.9%) i/s -    4364800 in  19.969401s
    
    After
    -----
    
    Calculating -------------------------------------
                              8743 i/100ms
    -------------------------------------------------
                           206525.9 (±17.8%) i/s -    4039266 in  19.992590s
Commits on Nov 9, 2012
  1. Jon Leighton

    Properly deprecate ConnectionHandler#connection_pools

    jonleighton authored
    Rather than just changing it and hoping for the best.
    
    Requested by @jeremy:
    
    ba1544d#commitcomment-2106059
Commits on Oct 26, 2012
  1. Jon Leighton

    Remove ActiveRecord::Model

    jonleighton authored
    In the end I think the pain of implementing this seamlessly was not
    worth the gain provided.
    
    The intention was that it would allow plain ruby objects that might not
    live in your main application to be subclassed and have persistence
    mixed in. But I've decided that the benefit of doing that is not worth
    the amount of complexity that the implementation introduced.
Commits on Sep 20, 2012
  1. Francesco Rodríguez
Something went wrong with that request. Please try again.