advanced_connection 0.5.13 → 0.5.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6d9bda6b436e364dda841af17bf2b2915d3e261d
4
- data.tar.gz: 6248d54d405b47f4bb26d8c38d3a102b71d78342
3
+ metadata.gz: 177ee27347e2d89c59e62a37e9c4277581a98a3e
4
+ data.tar.gz: 5f986bcfddcf5aae95f198c9b83f9ca03f81d94f
5
5
  SHA512:
6
- metadata.gz: 4ad06944f5895088cdf3c3b0edb8fea2f329a8f77b9a77ec5a0f76fe73fa6ca7d63f61c99d6227fa7a1302e817efc780b0cb97c126604976c3f1c7caf125db4c
7
- data.tar.gz: 7d7ae267de0aa0973ea4ad381c01b8ce9ec07ee65f1be3dcb65672ed79e46e1ca2389e97559d12b7d99c15ea5edd1d27a07aaf700a4bf1f64a6ebfb802ed76b4
6
+ metadata.gz: 65cc5f19566474a2f05244f5025a2f14046a15a07a0069ee0cf1134cdfd76ad73299544cd0676c2eb8ed8b7b56a4758616fa1989095374e7e774b608927ff2cd
7
+ data.tar.gz: fc36d53db639a0c22f2723421e924147b898226a917590ca97df10a2d26e243cca13adf798ded82c3b5abece1d683ba2a197187411d22fd670b24e161790beec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- advanced_connection (0.5.13)
4
+ advanced_connection (0.5.14)
5
5
  activerecord (~> 4.1)
6
6
  activesupport (~> 4.1)
7
7
  rails (~> 4.1)
@@ -48,6 +48,7 @@ GEM
48
48
  builder (3.2.2)
49
49
  coderay (1.1.1)
50
50
  concurrent-ruby (1.0.1)
51
+ concurrent-ruby (1.0.1-java)
51
52
  coveralls (0.8.13)
52
53
  json (~> 1.8)
53
54
  simplecov (~> 0.11.0)
@@ -96,6 +97,7 @@ GEM
96
97
  nenv (0.3.0)
97
98
  nokogiri (1.6.7.2)
98
99
  mini_portile2 (~> 2.0.0.rc2)
100
+ nokogiri (1.6.7.2-java)
99
101
  notiffany (0.0.8)
100
102
  nenv (~> 0.1)
101
103
  shellany (~> 0.0)
@@ -184,6 +186,7 @@ GEM
184
186
  tins (~> 1.0)
185
187
  thor (0.19.1)
186
188
  thread_safe (0.3.5)
189
+ thread_safe (0.3.5-java)
187
190
  tins (1.6.0)
188
191
  tzinfo (1.2.2)
189
192
  thread_safe (~> 0.1)
@@ -48,5 +48,31 @@ module AdvancedConnection::ActiveRecordExt
48
48
  def idle_time
49
49
  (in_use? ? 0.0 : Time.now - @last_checked_in).to_f
50
50
  end
51
+
52
+ def idle?
53
+ idle_time > pool.max_idle_time
54
+ end
55
+
56
+ def <=>(other)
57
+ case pool.queue_type
58
+ when :prefer_younger then
59
+ # when prefering younger, we sort oldest->youngest
60
+ # this ensures that older connections will be culled
61
+ # during #remove_idle_connections()
62
+ -(instance_age <=> other.instance_age)
63
+ when :prefer_older then
64
+ # when prefering older, we sort youngest->oldest
65
+ # this ensures that younger connections will be culled
66
+ # during #remove_idle_connections()
67
+ (instance_age <=> other.instance_age)
68
+ else
69
+ # with fifo / lifo queues, we only care about the
70
+ # last time a given connection was used (inferred
71
+ # by when it was last checked into the pool).
72
+ # This ensures that the longer idling connections
73
+ # will be culled.
74
+ -(last_checked_in <=> other.last_checked_in)
75
+ end
76
+ end
51
77
  end
52
78
  end
@@ -142,6 +142,10 @@ module AdvancedConnection::ActiveRecordExt
142
142
  @idle_manager = IdleManager.new(self, idle_check_interval).tap(&:start)
143
143
  end
144
144
 
145
+ #
146
+ ## SETINGS
147
+ #
148
+
145
149
  def queue_type
146
150
  @queue_type ||= spec.config.fetch(:queue_type,
147
151
  AdvancedConnection.connection_pool_queue_type).to_s.downcase.to_sym
@@ -191,74 +195,27 @@ module AdvancedConnection::ActiveRecordExt
191
195
 
192
196
  def checkin_with_last_checked_in(conn)
193
197
  conn.last_checked_in = Time.now
194
- idle_manager.debug "checking in connection #{conn.object_id} at #{conn.last_checked_in}"
198
+ idle_manager.log_debug "checking in connection #{conn.object_id} at #{conn.last_checked_in}"
195
199
  checkin_without_last_checked_in(conn)
196
200
  end
197
201
 
198
- def active_connections
199
- @connections.select(&:in_use?)
200
- end
201
-
202
- def available_connections
203
- @connections.reject(&:in_use?)
204
- end
205
-
206
202
  def idle_connections
207
- available_connections.select do |conn|
208
- (Time.now - conn.last_checked_in).to_f > max_idle_time
209
- end.sort { |a, b|
210
- case queue_type
211
- when :prefer_younger then
212
- # when prefering younger, we sort oldest->youngest
213
- # this ensures that older connections will be culled
214
- # during #remove_idle_connections()
215
- -(a.instance_age <=> b.instance_age)
216
- when :prefer_older then
217
- # when prefering older, we sort youngest->oldest
218
- # this ensures that younger connections will be culled
219
- # during #remove_idle_connections()
220
- (a.instance_age <=> b.instance_age)
221
- else
222
- # with fifo / lifo queues, we only care about the
223
- # last time a given connection was used (inferred
224
- # by when it was last checked into the pool).
225
- # This ensures that the longer idling connections
226
- # will be culled.
227
- -(a.last_checked_in <=> b.last_checked_in)
228
- end
229
- }
203
+ synchronize { @connections.select(&:idle?).sort }
230
204
  end
231
205
 
232
206
  def pool_statistics
233
- idle = active = available = 0
234
207
  synchronize do
235
- idle = idle_connections.size
236
- active = active_connections.size
237
- available = available_connections.size
238
- end
239
- total = active + available
240
-
241
- ActiveSupport::OrderedOptions.new.merge(
242
- total: total,
243
- idle: idle,
244
- active: active,
245
- available: available
246
- )
247
- end
248
-
249
- def warmup_connections(count = nil)
250
- count ||= warmup_connection_count
251
- slots = connection_limit - @connections.size
252
- count = slots if slots < count
253
-
254
- return unless slots >= count
255
-
256
- idle_manager.log_info "Warming up #{count} connection#{count > 1 ? 's' : ''}"
257
- synchronize do
258
- count.times {
259
- conn = checkout_new_connection
260
- @available.add conn
261
- }
208
+ total = @connections.size
209
+ idle = @connections.count(&:idle?)
210
+ active = @connections.count(&:in_use?)
211
+ available = total - active
212
+
213
+ ActiveSupport::OrderedOptions.new.merge(
214
+ total: total,
215
+ idle: idle,
216
+ active: active,
217
+ available: available
218
+ )
262
219
  end
263
220
  end
264
221
 
@@ -280,6 +237,22 @@ module AdvancedConnection::ActiveRecordExt
280
237
  warmup_connections(create_count)
281
238
  end
282
239
 
240
+ def warmup_connections(count = nil)
241
+ count ||= warmup_connection_count
242
+ slots = connection_limit - @connections.size
243
+ count = slots if slots < count
244
+
245
+ return unless slots >= count
246
+
247
+ idle_manager.log_info "Warming up #{count} connection#{count > 1 ? 's' : ''}"
248
+ synchronize do
249
+ count.times {
250
+ conn = checkout_new_connection
251
+ @available.add conn
252
+ }
253
+ end
254
+ end
255
+
283
256
  def remove_idle_connections
284
257
  # don't attempt to remove idle connections if we have threads waiting
285
258
  if @available.num_waiting > 0
@@ -22,7 +22,7 @@
22
22
  module AdvancedConnection
23
23
  MAJOR = 0
24
24
  MINOR = 5
25
- PATCH = 13
25
+ PATCH = 14
26
26
 
27
27
  VERSION = "%d.%d.%d" % [ MAJOR, MINOR, PATCH ]
28
28
  GEM_VERSION = Gem::Version.new(VERSION)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: advanced_connection
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.13
4
+ version: 0.5.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carl P. Corliss
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-12 00:00:00.000000000 Z
11
+ date: 2016-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails