sidekiq-throttled-worker 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -1
- data/lib/sidekiq/throttled_worker/fetch.rb +6 -2
- data/lib/sidekiq/throttled_worker/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 91197aecff6a9c46cb3c1435c85bdf1b74e5be216bbd9a89396fbdb6f00beb8b
|
4
|
+
data.tar.gz: c04884068ab7d1401460dead6edf0c029760dbe89a77d0490ecbbed7164609de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a7ee4c386dbdae03b4a41aa2a26d70e8825286708e207486d83f9514c91018c8f2ed7fd00ce9cc698c91d0cf4d682a76e3f3296199047c8b045b9bd5d94f3ba
|
7
|
+
data.tar.gz: 7cfa3edc88f5ef7dcfd9932894fbd07b3a541366e4c0b53ca5613035eb5c17c8f2e48ac0cdb76df5a2aa9bd4fd3e85c60ff58057835fc3b14b2d068d7a89f6f4
|
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
Sidekiq concurrency limit per worker in whole cluster, inspired by [sidekiq-throttled](https://github.com/sensortower/sidekiq-throttled). This gem only support concurrency, and try to avoid use lua in redis to reduce redis CPU usage.
|
4
4
|
|
5
|
+
This gem was designed to limit concurrency for some sensitive resources, e.g., databases and http requests, without concurrency limit, sidekiq may crush this services. When some worker exceed concurrency limit, this gem may try to slow down sidekiq process. Concurrency limit should only be use to in extreme case, you should not use this gem to limit business logic
|
6
|
+
|
5
7
|
## Installation
|
6
8
|
|
7
9
|
Add this line to your application's Gemfile:
|
@@ -29,7 +31,7 @@ Sidekiq::ThrottledWorker.setup!
|
|
29
31
|
|
30
32
|
This gem add two options attr in `sidekiq_options` func:
|
31
33
|
|
32
|
-
* `concurrency` : limit concurrency with current worker in whole cluster. Default is `nil` , which mean on limit
|
34
|
+
* `concurrency` : limit concurrency with current worker in whole cluster. Default is `nil` , which mean on limit
|
33
35
|
* `concurrency_ttl` : max worker run time, and worker may be block completely max for `concurrency_ttl` in extreme case. Default is 900, in most cases, you do not need change this.
|
34
36
|
|
35
37
|
Here is an example worker
|
@@ -12,8 +12,12 @@ module Sidekiq
|
|
12
12
|
return work if worker_class.get_sidekiq_options["concurrency"].nil?
|
13
13
|
|
14
14
|
if Concurrency.limit?(worker_class, job_hash['jid'])
|
15
|
-
|
16
|
-
|
15
|
+
job_hash["concurrency_limit_count"] ||= 0
|
16
|
+
job_hash["concurrency_limit_count"] += 1
|
17
|
+
sleep(rand * [(job_hash["concurrency_limit_count"] - 1) * 0.01, 0.1].min)
|
18
|
+
Sidekiq.redis do |conn|
|
19
|
+
conn.lpush("queue:#{work.queue_name}", Sidekiq.dump_json(job_hash)) # put in queue end to auto wait some time in busy sidekiq cluster
|
20
|
+
end
|
17
21
|
nil
|
18
22
|
else
|
19
23
|
work
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq-throttled-worker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- xuxiangyang
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-10-
|
11
|
+
date: 2020-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sidekiq
|