Parent

ActiveRecord::ConnectionAdapters::ConnectionPool

ActiveRecord’s connection pool is based on threads. Since we are working with EM and a single thread, multiple fiber design, we need to provide our own connection pool that keys off of Fiber.current so that different fibers running in the same thread don’t try to use the same connection.

Public Class Methods

new(spec) click to toggle source
    # File lib/active_record/fiber_patches.rb, line 52
52:       def initialize(spec)
53:         @spec = spec
54: 
55:         # The cache of reserved connections mapped to threads
56:         @reserved_connections = {}
57: 
58:         # The mutex used to synchronize pool access
59:         @connection_mutex = FiberedMonitor.new
60:         @queue = @connection_mutex.new_cond
61: 
62:         # default 5 second timeout unless on ruby 1.9
63:         @timeout = spec.config[:wait_timeout] || 5
64: 
65:         # default max pool size to 5
66:         @size = (spec.config[:pool] && spec.config[:pool].to_i) || 5
67: 
68:         @connections = []
69:         @checked_out = []
70:       end

Private Instance Methods

checkout_and_verify(c) click to toggle source
     # File lib/active_record/fiber_patches.rb, line 95
 95:       def checkout_and_verify(c)
 96:         @checked_out << c
 97:         c.run_callbacks :checkout
 98:         c.verify!
 99:         c
100:       end
remove_stale_cached_threads!(cache, &block) click to toggle source

Remove stale fibers from the cache.

    # File lib/active_record/fiber_patches.rb, line 79
79:       def remove_stale_cached_threads!(cache, &block)
80:         keys = Set.new(cache.keys)
81: 
82:         ActiveRecord::ConnectionAdapters.fiber_pools.each do |pool|
83:           pool.busy_fibers.each_pair do |object_id, fiber|
84:             keys.delete(object_id)
85:           end
86:         end
87: 
88:         keys.each do |key|
89:           next unless cache.has_key?(key)
90:           block.call(key, cache[key])
91:           cache.delete(key)
92:         end
93:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.