pgtk 0.22.0 → 0.22.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 902941bbf98d37acfad72c9615282264148e6ad6ce1183f2fcd085d3a0cf288e
4
- data.tar.gz: 00a5488c8dd99f98df1ebce8cef20207514964a1628df8489bd320d0c199ca77
3
+ metadata.gz: 0dc255f274b10a4bc7fe0a0e4d6c2a68a918957e571a147062325baf77d91db1
4
+ data.tar.gz: 971da231e5ff704bf28d28f3655f170ab986327da714cd3f27bade9ff784c6bd
5
5
  SHA512:
6
- metadata.gz: 47d6993b709ebce71a8cd1525f94230b8c554a8c2edd871ca67627ce6e6724d46ea3530827fa3cb653ae54b56cf4299cb4291197d3f870e602942ffc0b7b6134
7
- data.tar.gz: cbe8bf7eebf1c038d71079845355d805bc647be88e62523db89180ce9f39e4299a779f104ee648a1f4399f18f90a0e4f3aab371f277df964dec843299b5b733d
6
+ metadata.gz: d65bd86d962357d89353daa86da5cd10f255cd1840198217963fe854cc83805c44c5fbff48e4c109871a29d17f8d6c93932a2a186b4067d6be28348cc631e174
7
+ data.tar.gz: ed61c3ae252043956524564e4a4a6b087d9df684b83c509d3f92291d721e2840cdd21fbc0535bbd027bb6b436c3164518b710a8f7ecae68ff4b6a12980e83864
data/Gemfile CHANGED
@@ -16,6 +16,7 @@ gem 'rubocop-performance', '~>1.25', require: false
16
16
  gem 'rubocop-rake', '~>0.7', require: false
17
17
  gem 'simplecov', '~>0.22', require: false
18
18
  gem 'simplecov-cobertura', '~>3.0'
19
+ gem 'threads', '~>0.4'
19
20
  gem 'timeout', '~>0.4'
20
21
  gem 'xcop', '~>0.8', require: false
21
22
  gem 'yard', '~>0.9', require: false
data/Gemfile.lock CHANGED
@@ -102,6 +102,9 @@ GEM
102
102
  simplecov_json_formatter (0.1.4)
103
103
  slop (4.10.1)
104
104
  tago (0.3.0)
105
+ threads (0.4.1)
106
+ backtrace (~> 0)
107
+ concurrent-ruby (~> 1.0)
105
108
  timeout (0.4.4)
106
109
  unicode-display_width (3.2.0)
107
110
  unicode-emoji (~> 4.1)
@@ -132,6 +135,7 @@ DEPENDENCIES
132
135
  rubocop-rake (~> 0.7)
133
136
  simplecov (~> 0.22)
134
137
  simplecov-cobertura (~> 3.0)
138
+ threads (~> 0.4)
135
139
  timeout (~> 0.4)
136
140
  xcop (~> 0.8)
137
141
  yard (~> 0.9)
data/lib/pgtk/pool.rb CHANGED
@@ -74,7 +74,42 @@ class Pgtk::Pool
74
74
  " PgSQL version: #{version}",
75
75
  " #{@pool.size} connections:",
76
76
  @pool.map do |c|
77
- " ##{c.backend_pid} #{c.pipeline_status} #{c.status} #{c.transaction_status}"
77
+ [
78
+ ' ',
79
+ "##{c.backend_pid}",
80
+ case c.pipeline_status
81
+ when PG::Constants::PQ_PIPELINE_ON
82
+ 'ON'
83
+ when PG::Constants::PQ_PIPELINE_OFF
84
+ 'OFF'
85
+ when PG::Constants::PQ_PIPELINE_ABORTED
86
+ 'ABORTED'
87
+ else
88
+ "pipeline_status=#{c.pipeline_status}"
89
+ end,
90
+ case c.status
91
+ when PG::Constants::CONNECTION_OK
92
+ 'OK'
93
+ when PG::Constants::CONNECTION_BAD
94
+ 'BAD'
95
+ else
96
+ "status=#{c.status}"
97
+ end,
98
+ case c.transaction_status
99
+ when PG::Constants::PQTRANS_IDLE
100
+ 'IDLE'
101
+ when PG::Constants::PQTRANS_ACTIVE
102
+ 'ACTIVE'
103
+ when PG::Constants::PQTRANS_INTRANS
104
+ 'INTRANS'
105
+ when PG::Constants::PQTRANS_INERROR
106
+ 'INERROR'
107
+ when PG::Constants::PQTRANS_UNKNOWN
108
+ 'UNKNOWN'
109
+ else
110
+ "transaction_status=#{c.transaction_status}"
111
+ end
112
+ ].join(' ')
78
113
  end
79
114
  ].flatten.join("\n")
80
115
  end
data/lib/pgtk/stash.rb CHANGED
@@ -60,6 +60,7 @@ class Pgtk::Stash
60
60
  @max_queue_length = max_queue_length
61
61
  @threads = threads
62
62
  @loog = loog
63
+ @tpool = Concurrent::FixedThreadPool.new(@threads)
63
64
  end
64
65
 
65
66
  # Start a new connection pool with the given arguments.
@@ -90,9 +91,12 @@ class Pgtk::Stash
90
91
  '',
91
92
  "Pgtk::Stash (refill_interval=#{@refill_interval}s, max_queue_length=#{@max_queue_length}, threads=#{@threads}):",
92
93
  " #{'not ' if @launched.false?}launched",
93
- " #{@stash[:tables].count} tables in cache",
94
- " #{@stash[:queries].count} queries in cache:",
95
- qq.sort_by { -_1[2] }.take(64).map { |a| " #{a[1]}/#{a[2]}p/#{a[3]}s: #{a[0]}" }
94
+ " #{@tpool.queue_length} task(s) in the thread pool",
95
+ " #{@stash[:tables].count} table(s) in cache",
96
+ " #{qq.sum { |a| a[3] }} stale quer(ies) in cache:",
97
+ qq.select { |a| a[3].positive? }.sort_by { -_1[2] }.take(16).map { |a| " #{a[1]}/#{a[2]}p/#{a[3]}s: #{a[0]}" },
98
+ " #{qq.count { |a| a[3].zero? }} other quer(ies) in cache:",
99
+ qq.select { |a| a[3].zero? }.sort_by { -_1[2] }.take(8).map { |a| " #{a[1]}/#{a[2]}p/#{a[3]}s: #{a[0]}" }
96
100
  ].join("\n")
97
101
  end
98
102
 
@@ -171,34 +175,32 @@ class Pgtk::Stash
171
175
 
172
176
  def launch!
173
177
  raise 'Cannot launch multiple times on same cache data' unless @launched.make_true
174
- Concurrent::FixedThreadPool.new(@threads).then do |tpool|
175
- Concurrent::TimerTask.execute(execution_interval: 60 * 60, executor: tpool) do
176
- @entrance.with_write_lock do
177
- @stash[:queries].each_key do |q|
178
- @stash[:queries][q].each_key do |k|
179
- @stash[:queries][q][k][:popularity] = 0
180
- end
178
+ Concurrent::TimerTask.execute(execution_interval: 60 * 60, executor: @tpool) do
179
+ @entrance.with_write_lock do
180
+ @stash[:queries].each_key do |q|
181
+ @stash[:queries][q].each_key do |k|
182
+ @stash[:queries][q][k][:popularity] = 0
181
183
  end
182
184
  end
183
185
  end
184
- Concurrent::TimerTask.execute(execution_interval: @refill_interval, executor: tpool) do
185
- @stash[:queries]
186
- .map { |k, v| [k, v.values.sum { |vv| vv[:popularity] }, v.values.any? { |vv| vv[:stale] }] }
187
- .select { _1[2] }
188
- .sort_by { -_1[1] }
189
- .each do |a|
190
- q = a[0]
191
- @stash[:queries][q].each_key do |k|
192
- next unless @stash[:queries][q][k][:stale]
193
- next if tpool.queue_length >= @max_queue_length
194
- tpool.post do
186
+ end
187
+ Concurrent::TimerTask.execute(execution_interval: @refill_interval, executor: @tpool) do
188
+ @stash[:queries]
189
+ .map { |k, v| [k, v.values.sum { |vv| vv[:popularity] }, v.values.any? { |vv| vv[:stale] }] }
190
+ .select { _1[2] }
191
+ .sort_by { -_1[1] }
192
+ .each do |a|
193
+ q = a[0]
194
+ @stash[:queries][q].each_key do |k|
195
+ next unless @stash[:queries][q][k][:stale]
196
+ next if @tpool.queue_length >= @max_queue_length
197
+ @tpool.post do
198
+ h = @stash[:queries][q][k]
199
+ ret = @pool.exec(q, h[:params], h[:result])
200
+ @entrance.with_write_lock do
195
201
  h = @stash[:queries][q][k]
196
- ret = @pool.exec(q, h[:params], h[:result])
197
- @entrance.with_write_lock do
198
- h = @stash[:queries][q][k]
199
- h[:stale] = false
200
- h[:ret] = ret
201
- end
202
+ h[:stale] = false
203
+ h[:ret] = ret
202
204
  end
203
205
  end
204
206
  end
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.22.0'
14
+ VERSION = '0.22.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.22.0
4
+ version: 0.22.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko