sidekiq_autoscale 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +28 -0
- data/lib/sidekiq_autoscale/middleware.rb +4 -3
- data/lib/sidekiq_autoscale/sidekiq_interface.rb +13 -2
- data/lib/sidekiq_autoscale/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c14aa75694a405dd997f4a4e8a9e297a6ec2a957e0078d035db9ae92b065f7a
|
4
|
+
data.tar.gz: 4f030dce2047184464704ca840972bc799659ec9166920f4d25cf3c5644f1f9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a5f0bb27e64217815151abd036916a4d008da51588289aabc5bb37605dbff3113612b62535cdd4e1e67f9e9def73a01bba2e0b974b94483506d6acaee331ae3
|
7
|
+
data.tar.gz: 58f577a67b120d2a2e8bb90fcc3dc4cef6706f99544b1bf5e1805c6e09af68fba25477f7e2b769cba85330ab57ee8980387d704377c01a68ef940164d2b8259d
|
data/README.md
CHANGED
@@ -148,5 +148,33 @@ metadata:
|
|
148
148
|
|
149
149
|
Then assign your sidekiq deployment the `myapp-sidekiq` service account.
|
150
150
|
|
151
|
+
## Multiple sidekiq pools
|
152
|
+
|
153
|
+
Sidekiq autoscaler works with multiple Sidekiq pools that run off a single redis instance.
|
154
|
+
|
155
|
+
A typical use case for this would be a client pushing jobs to the same Redis backend,
|
156
|
+
which are then processed by multiple sets of workers (i.e. high CPU vs. high memory instances).
|
157
|
+
|
158
|
+
If so, you need to set two environment variables in each pool:
|
159
|
+
* `SIDEKIQ_QUEUES` - list of queues to be processed
|
160
|
+
* `SIDEKIQ_POOL` - name of the pool
|
161
|
+
|
162
|
+
You also need to use `$SIDEKIQ_POOL` tag when starting sidekiq processs.
|
163
|
+
|
164
|
+
Example:
|
165
|
+
|
166
|
+
```
|
167
|
+
# High priority pool
|
168
|
+
SIDEKIQ_QUEUES='["critical", "urgent"]'
|
169
|
+
SIDEKIQ_POOL=high
|
170
|
+
|
171
|
+
# Low priority pool
|
172
|
+
SIDEKIQ_QUEUES='["default", "low", "searchkick"]'
|
173
|
+
SIDEKIQ_POOL=low
|
174
|
+
|
175
|
+
# Start sidekiq
|
176
|
+
bundle exec sidekiq -C config/sidekiq.yml -g $SIDEKIQ_POOL
|
177
|
+
```
|
178
|
+
|
151
179
|
## License
|
152
180
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -2,10 +2,11 @@
|
|
2
2
|
|
3
3
|
module SidekiqAutoscale
|
4
4
|
class Middleware
|
5
|
-
|
6
|
-
|
5
|
+
POOL_NAME = ENV.fetch("SIDEKIQ_POOL", "default")
|
6
|
+
LAST_SCALED_AT_EVENT_KEY = "sidekiq_autoscaling:#{POOL_NAME}:last_scaled_at"
|
7
|
+
SCALING_LOCK_KEY = "sidekiq_autoscaling:#{POOL_NAME}:scaling_lock"
|
7
8
|
LOG_TAG = "[SIDEKIQ_SCALE][SCALING_EVENT]"
|
8
|
-
WORKER_COUNT_KEY = "sidekiq_autoscaling/current_worker_count"
|
9
|
+
WORKER_COUNT_KEY = "sidekiq_autoscaling/#{POOL_NAME}/current_worker_count"
|
9
10
|
|
10
11
|
# @param [Object] worker the worker instance
|
11
12
|
# @param [Hash] job the full job payload
|
@@ -9,7 +9,12 @@ module SidekiqAutoscale
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def queue_names
|
12
|
-
|
12
|
+
from_env = ENV["SIDEKIQ_QUEUES"]
|
13
|
+
if from_env
|
14
|
+
JSON.parse(from_env)
|
15
|
+
else
|
16
|
+
::Sidekiq::Queue.all.map(&:name)
|
17
|
+
end
|
13
18
|
end
|
14
19
|
|
15
20
|
def busy_threads
|
@@ -39,7 +44,13 @@ module SidekiqAutoscale
|
|
39
44
|
private
|
40
45
|
|
41
46
|
def process_set
|
42
|
-
@process_set ||=
|
47
|
+
@process_set ||= begin
|
48
|
+
ps = ::Sidekiq::ProcessSet.new
|
49
|
+
pool = ENV["SIDEKIQ_POOL"]
|
50
|
+
|
51
|
+
ps = ps.select {|process| process.tag == pool } if pool
|
52
|
+
ps
|
53
|
+
end
|
43
54
|
end
|
44
55
|
end
|
45
56
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq_autoscale
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Allen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-03-
|
11
|
+
date: 2022-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -56,14 +56,14 @@ dependencies:
|
|
56
56
|
name: railties
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 5.2.6
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 5.2.6
|
69
69
|
- !ruby/object:Gem::Dependency
|