pgtk 0.24.3 → 0.24.4

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: bc06629facf30f84cc049cd8404c347129c286edfd82c15d75382930d44456aa
4
- data.tar.gz: 27a43238939e20b6b8aa5356924fd2a18e10d78c10190dda446cea2c57edf004
3
+ metadata.gz: 5eb38e8d785a444233248ed07fe7ba2316b947b1b3a779f7738145cff4d56306
4
+ data.tar.gz: 8870ff5a0a87c911439618b6d26c9e42a9bb37edcf14182b4067d208774794a9
5
5
  SHA512:
6
- metadata.gz: 17d9b5d89759f159db6f0dea44a679bda49d05005b4f2215d2d174f8e92a09dbcb1ce5388e01fcf1ce7a0c6105dd2c4968f428f9c9a640946e4e14dcffeffd54
7
- data.tar.gz: 14a6aff5628756724cd356e83345a1f111be05a006eab4aa034b1c397253dac72f293b68b218eb06d9d17a0a549ca0477081e34b658de8ff1c05cecbe577d0b6
6
+ metadata.gz: 15991d0bd081e1b4a35da843c346e2da28196f0fa682a5088de811f37cb027bb57134fc92444ffdd3c6aa29587ff974085d6cb02cf3852a6e23419efd9a8fb94
7
+ data.tar.gz: 5fcb874e760ad74bca1c04aa2291c444139dbb441b84ac60dfc5352ae81c1174db7d3e8884aed413919cdb0d5863bf6c0120642f44250481380a5b065319bd0d
data/lib/pgtk/stash.rb CHANGED
@@ -54,6 +54,9 @@ class Pgtk::Stash
54
54
  # this limit is exceeded
55
55
  # @param [Integer] cap_interval Interval in seconds between background tasks that enforce the cache size
56
56
  # cap by removing old queries
57
+ # @param [Integer] retire Maximum age in seconds to keep a query in cache after its latest usage
58
+ # @param [Integer] retire_interval Interval in seconds between background tasks that remove
59
+ # retired queries
57
60
  # @param [Loog] loog Logger instance for debugging and monitoring cache operations (default: null logger)
58
61
  # @param [Concurrent::ReentrantReadWriteLock] entrance Read-write lock for thread-safe cache access
59
62
  # shared across instances
@@ -67,6 +70,8 @@ class Pgtk::Stash
67
70
  threads: 4,
68
71
  cap: 10_000,
69
72
  cap_interval: 60,
73
+ retire: 15 * 60,
74
+ retire_interval: 60,
70
75
  loog: Loog::NULL,
71
76
  entrance: Concurrent::ReentrantReadWriteLock.new,
72
77
  launched: Concurrent::AtomicBoolean.new(false)
@@ -80,6 +85,8 @@ class Pgtk::Stash
80
85
  @threads = threads
81
86
  @cap = cap
82
87
  @cap_interval = cap_interval
88
+ @retire = retire
89
+ @retire_interval = retire_interval
83
90
  @loog = loog
84
91
  @tpool = Concurrent::FixedThreadPool.new(@threads)
85
92
  end
@@ -122,18 +129,28 @@ class Pgtk::Stash
122
129
  [
123
130
  @pool.dump,
124
131
  '',
125
- # rubocop:disable Layout/LineLength
126
- "Pgtk::Stash (refill_interval=#{@refill_interval}s, max_queue_length=#{@max_queue_length}, threads=#{@threads}, cap=#{@cap}, cap_interval=#{@cap_interval}s):",
127
- # rubocop:enable Layout/LineLength
132
+ [
133
+ 'Pgtk::Stash (',
134
+ [
135
+ "refill_interval=#{@refill_interval}s",
136
+ "max_queue_length=#{@max_queue_length}",
137
+ "threads=#{@threads}",
138
+ "cap=#{@cap}",
139
+ "cap_interval=#{@cap_interval}s",
140
+ "retire=#{@retire}",
141
+ "retire_interval=#{@retire_interval}s"
142
+ ].join(', '),
143
+ '):'
144
+ ].join,
128
145
  " #{'not ' if @launched.false?}launched",
129
- " #{stash_size} queries stashed (#{stash_size > @cap ? 'above' : 'below'} the cap)",
130
- " #{@tpool.queue_length} task(s) in the thread pool",
131
- " #{@stash[:tables].count} table(s) in cache",
132
- " #{qq.sum { |a| a[:s] }} stale quer(ies) in cache:",
146
+ " #{stash_size} queries cached (#{stash_size > @cap ? 'above' : 'below'} the cap)",
147
+ " #{@tpool.queue_length} tasks in the thread pool",
148
+ " #{@stash[:tables].count} tables in cache",
149
+ " #{qq.sum { |a| a[:s] }} stale queries in cache:",
133
150
  qq.select { |a| a[:s].positive? }.sort_by { -_1[:p] }.take(8).map do |a|
134
151
  " #{a[:c]}/#{a[:p]}p/#{a[:s]}s/#{a[:u].ago}: #{a[:q]}"
135
152
  end,
136
- " #{qq.count { |a| a[:s].zero? }} other quer(ies) in cache:",
153
+ " #{qq.count { |a| a[:s].zero? }} other queries in cache:",
137
154
  qq.select { |a| a[:s].zero? }.sort_by { -_1[:p] }.take(16).map do |a|
138
155
  " #{a[:c]}/#{a[:p]}p/#{a[:s]}s/#{a[:u].ago}: #{a[:q]}"
139
156
  end
@@ -249,6 +266,14 @@ class Pgtk::Stash
249
266
  end
250
267
  end
251
268
  end
269
+ Concurrent::TimerTask.execute(execution_interval: @retire_interval, executor: @tpool) do
270
+ @entrance.with_write_lock do
271
+ @stash[:queries].each_key do |q|
272
+ @stash[:queries][q].delete_if { |_, h| h[:used] < Time.now - @retire }
273
+ @stash[:queries].delete_if { |_, kk| kk.empty? }
274
+ end
275
+ end
276
+ end
252
277
  Concurrent::TimerTask.execute(execution_interval: @refill_interval, executor: @tpool) do
253
278
  @stash[:queries]
254
279
  .map { |k, v| [k, v.values.sum { |vv| vv[:popularity] }, v.values.any? { |vv| vv[:stale] }] }
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.24.3'
14
+ VERSION = '0.24.4'
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.24.3
4
+ version: 0.24.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko