pgtk 0.21.4 → 0.22.0

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
  SHA256:
3
- metadata.gz: 35204d3374563b14809ba4c71c020294c14f0914967e62157a8aa5b005816eb4
4
- data.tar.gz: ba2972020329f362a4c6ef818cb938bff243a64ea0d19c31d5028c5c3808a07d
3
+ metadata.gz: 902941bbf98d37acfad72c9615282264148e6ad6ce1183f2fcd085d3a0cf288e
4
+ data.tar.gz: 00a5488c8dd99f98df1ebce8cef20207514964a1628df8489bd320d0c199ca77
5
5
  SHA512:
6
- metadata.gz: 53afb6021dccbd51901eadb93ee5ac8dfce38d8a40f45f400e5b3f5994bc9f2a3a23e6dcb694b7bf7211a00f7195c1fda8871e22c06b56bea050c766d59d25f1
7
- data.tar.gz: 4973efc117e972436f4e447c730974918159a58d2120aeb94ad620ef163ad95756deeb957549c727facdc15a75a36e5c3632f1182bdfa0779c921ec50dc0e7fe
6
+ metadata.gz: 47d6993b709ebce71a8cd1525f94230b8c554a8c2edd871ca67627ce6e6724d46ea3530827fa3cb653ae54b56cf4299cb4291197d3f870e602942ffc0b7b6134
7
+ data.tar.gz: cbe8bf7eebf1c038d71079845355d805bc647be88e62523db89180ce9f39e4299a779f104ee648a1f4399f18f90a0e4f3aab371f277df964dec843299b5b733d
data/Gemfile.lock CHANGED
@@ -32,7 +32,7 @@ GEM
32
32
  logger (1.7.0)
33
33
  loog (0.6.1)
34
34
  logger (~> 1.0)
35
- minitest (5.26.0)
35
+ minitest (5.26.1)
36
36
  minitest-reporters (1.7.1)
37
37
  ansi
38
38
  builder
data/lib/pgtk/stash.rb CHANGED
@@ -39,15 +39,15 @@ class Pgtk::Stash
39
39
  # @option [Hash] queries Internal cache data (default: {})
40
40
  # @option [Hash] tables Internal cache data (default: {})
41
41
  # @param [Integer] refill_interval Interval in seconds for recalculate stale queries
42
- # @param [Integer] top Number of queries to recalculate
43
- # @param [Integer] threads Number of threads in threadpool
42
+ # @param [Integer] max_queue_length Number of refilling tasks in the queue
43
+ # @param [Integer] threads Number of threads in tpool
44
44
  # @param [Loog] loog Logger for debugging (default: null logger)
45
45
  def initialize(
46
46
  pool,
47
47
  stash: { queries: {}, tables: {} },
48
- refill_interval: 5,
49
- top: 100,
50
- threads: 5,
48
+ refill_interval: 16,
49
+ max_queue_length: 128,
50
+ threads: 4,
51
51
  loog: Loog::NULL,
52
52
  entrance: Concurrent::ReentrantReadWriteLock.new,
53
53
  launched: Concurrent::AtomicBoolean.new(false)
@@ -57,7 +57,7 @@ class Pgtk::Stash
57
57
  @launched = launched
58
58
  @entrance = entrance
59
59
  @refill_interval = refill_interval
60
- @top = top
60
+ @max_queue_length = max_queue_length
61
61
  @threads = threads
62
62
  @loog = loog
63
63
  end
@@ -88,11 +88,11 @@ class Pgtk::Stash
88
88
  [
89
89
  @pool.dump,
90
90
  '',
91
- "Pgtk::Stash (refill_interval=#{@refill_interval}s, top=#{@top}q, threads=#{@threads}t):",
91
+ "Pgtk::Stash (refill_interval=#{@refill_interval}s, max_queue_length=#{@max_queue_length}, threads=#{@threads}):",
92
92
  " #{'not ' if @launched.false?}launched",
93
93
  " #{@stash[:tables].count} tables in cache",
94
94
  " #{@stash[:queries].count} queries in cache:",
95
- qq.sort_by { -_1[2] }.take(20).map { |a| " #{a[1]}/#{a[2]}p/#{a[3]}s: #{a[0]}" }
95
+ qq.sort_by { -_1[2] }.take(64).map { |a| " #{a[1]}/#{a[2]}p/#{a[3]}s: #{a[0]}" }
96
96
  ].join("\n")
97
97
  end
98
98
 
@@ -158,7 +158,7 @@ class Pgtk::Stash
158
158
  t,
159
159
  stash: @stash,
160
160
  refill_interval: @refill_interval,
161
- top: @top,
161
+ max_queue_length: @max_queue_length,
162
162
  threads: @threads,
163
163
  loog: @loog,
164
164
  entrance: @entrance,
@@ -171,8 +171,8 @@ class Pgtk::Stash
171
171
 
172
172
  def launch!
173
173
  raise 'Cannot launch multiple times on same cache data' unless @launched.make_true
174
- Concurrent::FixedThreadPool.new(@threads).then do |threadpool|
175
- Concurrent::TimerTask.execute(execution_interval: 60 * 60, executor: threadpool) do
174
+ Concurrent::FixedThreadPool.new(@threads).then do |tpool|
175
+ Concurrent::TimerTask.execute(execution_interval: 60 * 60, executor: tpool) do
176
176
  @entrance.with_write_lock do
177
177
  @stash[:queries].each_key do |q|
178
178
  @stash[:queries][q].each_key do |k|
@@ -181,17 +181,17 @@ class Pgtk::Stash
181
181
  end
182
182
  end
183
183
  end
184
- Concurrent::TimerTask.execute(execution_interval: @refill_interval, executor: threadpool) do
184
+ Concurrent::TimerTask.execute(execution_interval: @refill_interval, executor: tpool) do
185
185
  @stash[:queries]
186
186
  .map { |k, v| [k, v.values.sum { |vv| vv[:popularity] }, v.values.any? { |vv| vv[:stale] }] }
187
187
  .select { _1[2] }
188
188
  .sort_by { -_1[1] }
189
- .first(@top)
190
189
  .each do |a|
191
190
  q = a[0]
192
191
  @stash[:queries][q].each_key do |k|
193
192
  next unless @stash[:queries][q][k][:stale]
194
- threadpool.post do
193
+ next if tpool.queue_length >= @max_queue_length
194
+ tpool.post do
195
195
  h = @stash[:queries][q][k]
196
196
  ret = @pool.exec(q, h[:params], h[:result])
197
197
  @entrance.with_write_lock do
data/lib/pgtk/version.rb CHANGED
@@ -11,5 +11,5 @@ require_relative '../pgtk'
11
11
  # License:: MIT
12
12
  module Pgtk
13
13
  # Current version of the library.
14
- VERSION = '0.21.4'
14
+ VERSION = '0.22.0'
15
15
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pgtk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.21.4
4
+ version: 0.22.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko