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 +4 -4
- data/lib/pgtk/stash.rb +33 -8
- 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: 5eb38e8d785a444233248ed07fe7ba2316b947b1b3a779f7738145cff4d56306
|
|
4
|
+
data.tar.gz: 8870ff5a0a87c911439618b6d26c9e42a9bb37edcf14182b4067d208774794a9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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
|
|
130
|
-
" #{@tpool.queue_length}
|
|
131
|
-
" #{@stash[:tables].count}
|
|
132
|
-
" #{qq.sum { |a| a[:s] }} stale
|
|
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
|
|
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