pgtk 0.28.0 → 0.28.1
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/lib/pgtk/stash.rb +68 -63
- 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: 15ef00bc464354f5067a8346303914924549a69127dd7d089511b432ceb61cb5
|
|
4
|
+
data.tar.gz: f0714a56d3d31bdc90f6a8b24bd871b4ac2256dabe32be94191afb92e2034f74
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 186a1581c002df615bef9ddecf615140ee0cfe4abd328f7ea841b891d09ffbb3f08ae058eb534abcb4c7002fd2b903d082e4b1d5a577b4f9d615a3b8ee8bd35d
|
|
7
|
+
data.tar.gz: efa556d86eea1b11834d8c19f3620abcc17d3567d3db0d9452d20c4cdd56ad59db13b38ecded753f86ca14f2d36fc95e7e2f67d43386246071ff3d65675bede0
|
data/lib/pgtk/stash.rb
CHANGED
|
@@ -116,67 +116,69 @@ class Pgtk::Stash
|
|
|
116
116
|
#
|
|
117
117
|
# @return [String] Multi-line text representation of the current cache state
|
|
118
118
|
def dump
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
@pool.dump,
|
|
131
|
-
'',
|
|
119
|
+
@entrance.with_read_lock do
|
|
120
|
+
qq =
|
|
121
|
+
@stash[:queries].map do |q, kk|
|
|
122
|
+
{
|
|
123
|
+
q: q.dup, # the query
|
|
124
|
+
c: kk.values.count, # how many keys?
|
|
125
|
+
p: kk.values.sum { |vv| vv[:popularity] }, # total popularity of all keys
|
|
126
|
+
s: kk.values.count { |vv| vv[:stale] }, # how many stale keys?
|
|
127
|
+
u: kk.values.map { |vv| vv[:used] }.max || Time.now # when was it used
|
|
128
|
+
}
|
|
129
|
+
end
|
|
132
130
|
[
|
|
133
|
-
|
|
131
|
+
@pool.dump,
|
|
132
|
+
'',
|
|
134
133
|
[
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
"
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
"
|
|
178
|
-
|
|
179
|
-
].
|
|
134
|
+
'Pgtk::Stash (',
|
|
135
|
+
[
|
|
136
|
+
"threads=#{@threads}",
|
|
137
|
+
"max_queue_length=#{@max_queue_length}",
|
|
138
|
+
if @refill_interval
|
|
139
|
+
[
|
|
140
|
+
"refill_interval=#{@refill_interval}s",
|
|
141
|
+
"refill_delay=#{@refill_delay}s"
|
|
142
|
+
]
|
|
143
|
+
else
|
|
144
|
+
'no refilling'
|
|
145
|
+
end,
|
|
146
|
+
if @cap_interval
|
|
147
|
+
[
|
|
148
|
+
"cap_interval=#{@cap_interval}s",
|
|
149
|
+
"cap=#{@cap}"
|
|
150
|
+
]
|
|
151
|
+
else
|
|
152
|
+
'no capping'
|
|
153
|
+
end,
|
|
154
|
+
if @retire_interval
|
|
155
|
+
[
|
|
156
|
+
"retire_interval=#{@retire_interval}s",
|
|
157
|
+
"retire=#{@retire}"
|
|
158
|
+
]
|
|
159
|
+
else
|
|
160
|
+
'no retirement'
|
|
161
|
+
end
|
|
162
|
+
].flatten.join(', '),
|
|
163
|
+
'):'
|
|
164
|
+
].join,
|
|
165
|
+
if @tpool
|
|
166
|
+
" #{@tpool.queue_length} tasks in the thread pool"
|
|
167
|
+
else
|
|
168
|
+
' Not launched yet'
|
|
169
|
+
end,
|
|
170
|
+
" #{stash_size} queries cached (#{stash_size > @cap ? 'above' : 'below'} the cap)",
|
|
171
|
+
" #{@stash[:tables].count} tables in cache",
|
|
172
|
+
" #{qq.sum { |a| a[:s] }} stale queries in cache:",
|
|
173
|
+
qq.select { |a| a[:s].positive? }.sort_by { -_1[:p] }.take(8).map do |a|
|
|
174
|
+
" #{a[:c]}/#{a[:p]}p/#{a[:s]}s/#{a[:u].ago}: #{a[:q]}"
|
|
175
|
+
end,
|
|
176
|
+
" #{qq.count { |a| a[:s].zero? }} other queries in cache:",
|
|
177
|
+
qq.select { |a| a[:s].zero? }.sort_by { -_1[:p] }.take(16).map do |a|
|
|
178
|
+
" #{a[:c]}/#{a[:p]}p/#{a[:s]}s/#{a[:u].ago}: #{a[:q]}"
|
|
179
|
+
end
|
|
180
|
+
].join("\n")
|
|
181
|
+
end
|
|
180
182
|
end
|
|
181
183
|
|
|
182
184
|
# Execute a SQL query with optional caching.
|
|
@@ -258,7 +260,9 @@ class Pgtk::Stash
|
|
|
258
260
|
#
|
|
259
261
|
# @return [Integer] Total count of cached query results
|
|
260
262
|
def stash_size
|
|
261
|
-
@
|
|
263
|
+
@entrance.with_write_lock do
|
|
264
|
+
@stash[:queries].values.sum { |kk| kk.values.size }
|
|
265
|
+
end
|
|
262
266
|
end
|
|
263
267
|
|
|
264
268
|
# Launch background tasks for cache management.
|
|
@@ -298,12 +302,13 @@ class Pgtk::Stash
|
|
|
298
302
|
end
|
|
299
303
|
return unless @refill_interval
|
|
300
304
|
Concurrent::TimerTask.execute(execution_interval: @refill_interval, executor: @tpool) do
|
|
301
|
-
|
|
305
|
+
qq =
|
|
306
|
+
@stash[:queries]
|
|
302
307
|
.map { |k, v| [k, v.values.sum { |vv| vv[:popularity] }, v.values.any? { |vv| vv[:stale] }] }
|
|
303
308
|
.select { _1[2] }
|
|
304
309
|
.sort_by { -_1[1] }
|
|
305
|
-
.
|
|
306
|
-
|
|
310
|
+
.map { |a| a[0] }
|
|
311
|
+
qq.each do |q|
|
|
307
312
|
@stash[:queries][q].each_key do |k|
|
|
308
313
|
next unless @stash[:queries][q][k][:stale]
|
|
309
314
|
next if @stash[:queries][q][k][:stale] > Time.now - @refill_delay
|
data/lib/pgtk/version.rb
CHANGED