advanced_connection 0.5.5 → 0.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5388815e17dd8184ac2da77dd66f12dc8f420c89
|
4
|
+
data.tar.gz: 84e79b7bcaa1806c872f25831c0b688843af0bf8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1f7d22818b463df971f7dde6a17b4f19dcd35c5a048b88863684bf9dbe685e99c8c0a8fdbdd5a044681fd951e779ce0ad06df83dc9e84dab8b251906d8e5024
|
7
|
+
data.tar.gz: c9a8fe419202cca4bce4d552c921cceb53d0e71b7b7ee861391172068d1c4670280d4bcf09ed69ce50500c3adce1369003ee01d2e22d9d4654701eae5de6adae
|
data/Gemfile.lock
CHANGED
@@ -179,7 +179,7 @@ module AdvancedConnection::ActiveRecordExt
|
|
179
179
|
total: total,
|
180
180
|
idle: idle,
|
181
181
|
active: active,
|
182
|
-
available: available
|
182
|
+
available: available
|
183
183
|
)
|
184
184
|
end
|
185
185
|
|
@@ -188,14 +188,14 @@ module AdvancedConnection::ActiveRecordExt
|
|
188
188
|
slots = connection_limit - @connections.size
|
189
189
|
count = slots if slots < count
|
190
190
|
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
191
|
+
return unless slots >= count
|
192
|
+
|
193
|
+
idle_info "Warming up #{count} connection#{count > 1 ? 's' : ''}"
|
194
|
+
synchronize do
|
195
|
+
count.times {
|
196
|
+
conn = checkout_new_connection
|
197
|
+
@available.add conn
|
198
|
+
}
|
199
199
|
end
|
200
200
|
end
|
201
201
|
|
@@ -224,22 +224,22 @@ module AdvancedConnection::ActiveRecordExt
|
|
224
224
|
idle_conns = idle_connections
|
225
225
|
idle_count = idle_conns.size
|
226
226
|
|
227
|
-
|
228
|
-
cull_count = (idle_count - max_idle_connections)
|
227
|
+
return unless idle_count > max_idle_connections
|
229
228
|
|
230
|
-
|
231
|
-
idle_conns.each_with_index do |conn, idx|
|
232
|
-
last_ci = (Time.now - conn.last_checked_in).to_f
|
233
|
-
if idx < cull_count
|
234
|
-
culled += remove_connection(conn) ? 1 : 0
|
235
|
-
idle_info "culled connection ##{idx} id##{conn.object_id} - age:#{conn.instance_age} last_checkin:#{last_ci}"
|
236
|
-
else
|
237
|
-
idle_info "kept connection ##{idx} id##{conn.object_id} - age:#{conn.instance_age} last_checkin:#{last_ci}"
|
238
|
-
end
|
239
|
-
end
|
229
|
+
cull_count = (idle_count - max_idle_connections)
|
240
230
|
|
241
|
-
|
231
|
+
culled = 0
|
232
|
+
idle_conns.each_with_index do |conn, idx|
|
233
|
+
last_ci = (Time.now - conn.last_checked_in).to_f
|
234
|
+
if idx < cull_count
|
235
|
+
culled += remove_connection(conn) ? 1 : 0
|
236
|
+
idle_info "culled connection ##{idx} id##{conn.object_id} - age:#{conn.instance_age} last_checkin:#{last_ci}"
|
237
|
+
else
|
238
|
+
idle_info "kept connection ##{idx} id##{conn.object_id} - age:#{conn.instance_age} last_checkin:#{last_ci}"
|
239
|
+
end
|
242
240
|
end
|
241
|
+
|
242
|
+
idle_info "culled %d connections" % culled
|
243
243
|
end
|
244
244
|
|
245
245
|
private
|
@@ -101,6 +101,13 @@ module AdvancedConnection
|
|
101
101
|
@config = DEFAULT_CONFIG.deep_dup
|
102
102
|
end
|
103
103
|
|
104
|
+
def can_enable?
|
105
|
+
# don't enable if we're running rake tasks, in particular db: or assets: tasks
|
106
|
+
return false if $0.include? 'rake'
|
107
|
+
return false if ARGV.grep(/^(assets|db):/).any?
|
108
|
+
true
|
109
|
+
end
|
110
|
+
|
104
111
|
def loaded!
|
105
112
|
@loaded = true
|
106
113
|
end
|
@@ -23,17 +23,19 @@ module AdvancedConnection
|
|
23
23
|
class Railtie < Rails::Railtie
|
24
24
|
config.advanced_connection = ActiveSupport::OrderedOptions.new
|
25
25
|
|
26
|
-
|
27
|
-
ActiveSupport.on_load(:
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
if AdvancedConnection.can_enable?
|
27
|
+
ActiveSupport.on_load(:before_initialize) do
|
28
|
+
ActiveSupport.on_load(:active_record) do
|
29
|
+
# load our intitializer ASAP so we can make use of user defined configuration
|
30
|
+
load Rails.root.join('config', 'initializers', 'advanced_connection.rb')
|
31
|
+
ActiveRecord::Base.send(:include, AdvancedConnection::ActiveRecordExt)
|
32
|
+
end
|
31
33
|
end
|
32
|
-
end
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
35
|
+
config.after_initialize do
|
36
|
+
if AdvancedConnection.enable_idle_connection_manager && AdvancedConnection.warmup_connections
|
37
|
+
ActiveRecord::Base.connection_handler.connection_pool_list.each(&:warmup_connections)
|
38
|
+
end
|
37
39
|
end
|
38
40
|
end
|
39
41
|
end
|