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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pgtk/stash.rb +68 -63
  3. data/lib/pgtk/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 757b15a689138f24c6ede8c373da30e0dce065bced0be49ecc1cde717fa44498
4
- data.tar.gz: b3d1f97cb77914eda80071362d7adbaf850e2b2db810b6cc3f6fdce6d1b51f69
3
+ metadata.gz: 15ef00bc464354f5067a8346303914924549a69127dd7d089511b432ceb61cb5
4
+ data.tar.gz: f0714a56d3d31bdc90f6a8b24bd871b4ac2256dabe32be94191afb92e2034f74
5
5
  SHA512:
6
- metadata.gz: c2d377b1dc85c5d499665f6c57118b9c7373e8026e80eb0a21ef1a1ef5b2decffa80cdd2225f1a89cfe43e120d32f96cd64e047c841611883fc3f5dee7683284
7
- data.tar.gz: 24f984d5f13d767514fd47b75920d3da94a0f6abfb4be0daf408d90846161a09c34b1607e4565a33ca3f3d5d61973496171d44f17eebab4aed50d558dd26628b
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
- qq =
120
- @stash[:queries].map do |q, kk|
121
- {
122
- q: q.dup, # the query
123
- c: kk.values.count, # how many keys?
124
- p: kk.values.sum { |vv| vv[:popularity] }, # total popularity of all keys
125
- s: kk.values.count { |vv| vv[:stale] }, # how many stale keys?
126
- u: kk.values.map { |vv| vv[:used] }.max || Time.now # when was it used
127
- }
128
- end
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
- 'Pgtk::Stash (',
131
+ @pool.dump,
132
+ '',
134
133
  [
135
- "threads=#{@threads}",
136
- "max_queue_length=#{@max_queue_length}",
137
- if @refill_interval
138
- [
139
- "refill_interval=#{@refill_interval}s",
140
- "refill_delay=#{@refill_delay}s"
141
- ]
142
- else
143
- 'no refilling'
144
- end,
145
- if @cap_interval
146
- [
147
- "cap_interval=#{@cap_interval}s",
148
- "cap=#{@cap}"
149
- ]
150
- else
151
- 'no capping'
152
- end,
153
- if @retire_interval
154
- [
155
- "retire_interval=#{@retire_interval}s",
156
- "retire=#{@retire}"
157
- ]
158
- else
159
- 'no retirement'
160
- end
161
- ].flatten.join(', '),
162
- '):'
163
- ].join,
164
- if @tpool
165
- " #{@tpool.queue_length} tasks in the thread pool"
166
- else
167
- ' Not launched yet'
168
- end,
169
- " #{stash_size} queries cached (#{stash_size > @cap ? 'above' : 'below'} the cap)",
170
- " #{@stash[:tables].count} tables in cache",
171
- " #{qq.sum { |a| a[:s] }} stale queries in cache:",
172
- qq.select { |a| a[:s].positive? }.sort_by { -_1[:p] }.take(8).map do |a|
173
- " #{a[:c]}/#{a[:p]}p/#{a[:s]}s/#{a[:u].ago}: #{a[:q]}"
174
- end,
175
- " #{qq.count { |a| a[:s].zero? }} other queries in cache:",
176
- qq.select { |a| a[:s].zero? }.sort_by { -_1[:p] }.take(16).map do |a|
177
- " #{a[:c]}/#{a[:p]}p/#{a[:s]}s/#{a[:u].ago}: #{a[:q]}"
178
- end
179
- ].join("\n")
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
- @stash[:queries].values.sum { |kk| kk.values.size }
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
- @stash[:queries]
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
- .each do |a|
306
- q = a[0]
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
@@ -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.28.0'
14
+ VERSION = '0.28.1'
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.28.0
4
+ version: 0.28.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko