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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/pgtk/stash.rb +14 -14
- data/lib/pgtk/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 902941bbf98d37acfad72c9615282264148e6ad6ce1183f2fcd085d3a0cf288e
|
|
4
|
+
data.tar.gz: 00a5488c8dd99f98df1ebce8cef20207514964a1628df8489bd320d0c199ca77
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 47d6993b709ebce71a8cd1525f94230b8c554a8c2edd871ca67627ce6e6724d46ea3530827fa3cb653ae54b56cf4299cb4291197d3f870e602942ffc0b7b6134
|
|
7
|
+
data.tar.gz: cbe8bf7eebf1c038d71079845355d805bc647be88e62523db89180ce9f39e4299a779f104ee648a1f4399f18f90a0e4f3aab371f277df964dec843299b5b733d
|
data/Gemfile.lock
CHANGED
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]
|
|
43
|
-
# @param [Integer] threads Number of threads in
|
|
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:
|
|
49
|
-
|
|
50
|
-
threads:
|
|
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
|
-
@
|
|
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,
|
|
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(
|
|
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
|
-
|
|
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 |
|
|
175
|
-
Concurrent::TimerTask.execute(execution_interval: 60 * 60, executor:
|
|
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:
|
|
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
|
-
|
|
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