sidekiq 7.0.3 → 7.1.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of sidekiq might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Changes.md +82 -9
- data/README.md +29 -22
- data/bin/sidekiqload +204 -109
- data/bin/sidekiqmon +3 -0
- data/lib/sidekiq/api.rb +33 -10
- data/lib/sidekiq/capsule.rb +1 -0
- data/lib/sidekiq/cli.rb +3 -2
- data/lib/sidekiq/client.rb +33 -20
- data/lib/sidekiq/component.rb +3 -1
- data/lib/sidekiq/config.rb +12 -4
- data/lib/sidekiq/embedded.rb +1 -1
- data/lib/sidekiq/fetch.rb +1 -1
- data/lib/sidekiq/job.rb +1 -5
- data/lib/sidekiq/job_retry.rb +8 -5
- data/lib/sidekiq/job_util.rb +49 -15
- data/lib/sidekiq/launcher.rb +3 -2
- data/lib/sidekiq/metrics/query.rb +1 -1
- data/lib/sidekiq/metrics/shared.rb +3 -3
- data/lib/sidekiq/metrics/tracking.rb +2 -0
- data/lib/sidekiq/middleware/chain.rb +12 -9
- data/lib/sidekiq/middleware/current_attributes.rb +55 -16
- data/lib/sidekiq/monitor.rb +1 -3
- data/lib/sidekiq/paginator.rb +1 -1
- data/lib/sidekiq/processor.rb +4 -1
- data/lib/sidekiq/rails.rb +10 -0
- data/lib/sidekiq/redis_client_adapter.rb +5 -24
- data/lib/sidekiq/scheduled.rb +1 -1
- data/lib/sidekiq/version.rb +1 -1
- data/lib/sidekiq/web/application.rb +14 -2
- data/lib/sidekiq/web/helpers.rb +2 -2
- data/lib/sidekiq/web.rb +1 -1
- data/sidekiq.gemspec +7 -15
- data/web/assets/javascripts/metrics.js +30 -2
- data/web/assets/stylesheets/application.css +1 -1
- data/web/locales/da.yml +11 -4
- data/web/locales/fr.yml +14 -0
- data/web/locales/gd.yml +99 -0
- data/web/locales/ja.yml +3 -1
- data/web/views/_footer.erb +2 -2
- data/web/views/_metrics_period_select.erb +12 -0
- data/web/views/busy.erb +3 -3
- data/web/views/metrics.erb +6 -4
- data/web/views/metrics_for_job.erb +11 -12
- metadata +14 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 587dc2a304b24daba86943907fe6b0285ecd302119e900e68403fcf0dedff163
|
4
|
+
data.tar.gz: 713489d61003baf22b07879e959048bede62a5b661cf37a6c43540cd3cd59eac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 026b2dd393d8e9774f1afa6fe4df9cfca70520e84a0d566dde668e535809492476004f205668d16bbe2d5f0111fb4d51a4ddddd60bfd6a1c90d906bcb50b5c92
|
7
|
+
data.tar.gz: 5b6769ef293543a4d7003e870c5ed5b1d9b7d44a941c4fc446afd16531fc1eaae2f684359fb7c093eb1761c517ff31c106f247c17a8e2808bb629adf47061a62
|
data/Changes.md
CHANGED
@@ -1,6 +1,74 @@
|
|
1
1
|
# Sidekiq Changes
|
2
2
|
|
3
|
-
[Sidekiq Changes](https://github.com/
|
3
|
+
[Sidekiq Changes](https://github.com/sidekiq/sidekiq/blob/main/Changes.md) | [Sidekiq Pro Changes](https://github.com/sidekiq/sidekiq/blob/main/Pro-Changes.md) | [Sidekiq Enterprise Changes](https://github.com/sidekiq/sidekiq/blob/main/Ent-Changes.md)
|
4
|
+
|
5
|
+
7.1.2
|
6
|
+
----------
|
7
|
+
|
8
|
+
- Mark Web UI assets as private so CDNs won't cache them [#5936]
|
9
|
+
- Fix stackoverflow when using Oj and the JSON log formatter [#5920]
|
10
|
+
- Remove spurious `enqueued_at` from scheduled ActiveJobs [#5937]
|
11
|
+
|
12
|
+
7.1.1
|
13
|
+
----------
|
14
|
+
|
15
|
+
- Support multiple CurrentAttributes [#5904]
|
16
|
+
- Speed up latency fetch with large queues on Redis <7 [#5910]
|
17
|
+
- Allow a larger default client pool [#5886]
|
18
|
+
- Ensure Sidekiq.options[:environment] == RAILS_ENV [#5932]
|
19
|
+
|
20
|
+
7.1.0
|
21
|
+
----------
|
22
|
+
|
23
|
+
- Improve display of ActiveJob arguments in Web UI [#5825, cover]
|
24
|
+
- Update `push_bulk` to push `batch_size` jobs at a time and allow laziness [#5827, fatkodima]
|
25
|
+
This allows Sidekiq::Client to push unlimited jobs as long as it has enough memory for the batch_size.
|
26
|
+
- Update `perform_bulk` to use `push_bulk` internally.
|
27
|
+
- Change return value of `push_bulk` to map 1-to-1 with arguments.
|
28
|
+
If you call `push_bulk(args: [[1], [2], [3]])`, you will now always get
|
29
|
+
an array of 3 values as the result: `["jid1", nil, "jid3"]` where nil means
|
30
|
+
that particular job did not push successfully (possibly due to middleware
|
31
|
+
stopping it). Previously nil values were removed so it was impossible to tell
|
32
|
+
which jobs pushed successfully and which did not.
|
33
|
+
- Migrate away from all deprecated Redis commands [#5788]
|
34
|
+
Sidekiq will now print a warning if you use one of those deprecated commands.
|
35
|
+
- Prefix all Sidekiq thread names [#5872]
|
36
|
+
|
37
|
+
7.0.9
|
38
|
+
----------
|
39
|
+
|
40
|
+
- Restore confirmation dialogs in Web UI [#5881, shevaun]
|
41
|
+
- Increase fetch timeout to minimize ReadTimeoutError [#5874]
|
42
|
+
- Reverse histogram tooltip ordering [#5868]
|
43
|
+
- Add Scottish Gaelic (gd) locale [#5867, GunChleoc]
|
44
|
+
|
45
|
+
7.0.8
|
46
|
+
----------
|
47
|
+
|
48
|
+
- **SECURITY** Sanitize `period` input parameter on Metrics pages.
|
49
|
+
Specially crafted values can lead to XSS. This functionality
|
50
|
+
was introduced in 7.0.4. Thank you to spercex @ huntr.dev [#5694]
|
51
|
+
- Add job hash as 3rd parameter to the `sidekiq_retry_in` block.
|
52
|
+
|
53
|
+
7.0.7
|
54
|
+
----------
|
55
|
+
|
56
|
+
- Fix redis-client API usage which could result in stuck Redis
|
57
|
+
connections [#5823]
|
58
|
+
- Fix AS::Duration with `sidekiq_retry_in` [#5806]
|
59
|
+
- Restore dumping config options on startup with `-v` [#5822]
|
60
|
+
|
61
|
+
7.0.5,7.0.6
|
62
|
+
----------
|
63
|
+
|
64
|
+
- More context for debugging json unsafe errors [#5787]
|
65
|
+
|
66
|
+
7.0.4
|
67
|
+
----------
|
68
|
+
|
69
|
+
- Performance and memory optimizations [#5768, fatkodima]
|
70
|
+
- Add 1-8 hour period selector to Metrics pages [#5694]
|
71
|
+
- Fix process display with `sidekiqmon` [#5733]
|
4
72
|
|
5
73
|
7.0.3
|
6
74
|
----------
|
@@ -48,6 +116,11 @@ end
|
|
48
116
|
- Job Execution metrics!!!
|
49
117
|
- See `docs/7.0-Upgrade.md` for release notes
|
50
118
|
|
119
|
+
6.5.9
|
120
|
+
----------
|
121
|
+
|
122
|
+
- Ensure Sidekiq.options[:environment] == RAILS_ENV [#5932]
|
123
|
+
|
51
124
|
6.5.8
|
52
125
|
----------
|
53
126
|
|
@@ -88,7 +161,7 @@ end
|
|
88
161
|
6.5.2
|
89
162
|
----------
|
90
163
|
|
91
|
-
- [Job Metrics are under active development, help wanted!](https://github.com/
|
164
|
+
- [Job Metrics are under active development, help wanted!](https://github.com/sidekiq/sidekiq/wiki/Metrics#contributing) **BETA**
|
92
165
|
- Add `Context` column on queue page which shows any CurrentAttributes [#5450]
|
93
166
|
- `sidekiq_retry_in` may now return `:discard` or `:kill` to dynamically stop job retries [#5406]
|
94
167
|
- Smarter sorting of processes in /busy Web UI [#5398]
|
@@ -107,7 +180,7 @@ end
|
|
107
180
|
- Substantial refactoring of Sidekiq server internals, part of a larger effort
|
108
181
|
to reduce Sidekiq's internal usage of global methods and data, see [docs/global_to_local.md](docs/global_to_local.md) and [docs/middleware.md](docs/middleware.md).
|
109
182
|
- **Add beta support for the `redis-client` gem**. This will become the default Redis driver in Sidekiq 7.0. [#5298]
|
110
|
-
Read more: https://github.com/
|
183
|
+
Read more: https://github.com/sidekiq/sidekiq/wiki/Using-redis-client
|
111
184
|
- **Add beta support for DB transaction-aware client** [#5291]
|
112
185
|
Add this line to your initializer and any jobs created during a transaction
|
113
186
|
will only be pushed to Redis **after the transaction commits**. You will need to add the
|
@@ -307,7 +380,7 @@ If this is a Rails app in API mode, you need to enable sessions.
|
|
307
380
|
---------
|
308
381
|
|
309
382
|
- **Integrate with systemd's watchdog and notification features** [#4488]
|
310
|
-
Set `Type=notify` in [sidekiq.service](https://github.com/
|
383
|
+
Set `Type=notify` in [sidekiq.service](https://github.com/sidekiq/sidekiq/blob/4b8a8bd3ae42f6e48ae1fdaf95ed7d7af18ed8bb/examples/systemd/sidekiq.service#L30-L39). The integration works automatically.
|
311
384
|
- Use `setTimeout` rather than `setInterval` to avoid thundering herd [#4480]
|
312
385
|
- Fix edge case where a job can be pushed without a queue.
|
313
386
|
- Flush job stats at exit [#4498]
|
@@ -320,7 +393,7 @@ If this is a Rails app in API mode, you need to enable sessions.
|
|
320
393
|
- Fix broken Web UI response when using NewRelic and Rack 2.1.2+. [#4440]
|
321
394
|
- Update APIs to use `UNLINK`, not `DEL`. [#4449]
|
322
395
|
- Fix Ruby 2.7 warnings [#4412]
|
323
|
-
- Add support for `APP_ENV` [[95fa5d9]](https://github.com/
|
396
|
+
- Add support for `APP_ENV` [[95fa5d9]](https://github.com/sidekiq/sidekiq/commit/95fa5d90192148026e52ca2902f1b83c70858ce8)
|
324
397
|
|
325
398
|
6.0.4
|
326
399
|
---------
|
@@ -432,7 +505,7 @@ Sidekiq.configure_server do |config|
|
|
432
505
|
config.log_formatter = Sidekiq::Logger::Formatters::JSON.new
|
433
506
|
end
|
434
507
|
```
|
435
|
-
See the [Logging wiki page](https://github.com/
|
508
|
+
See the [Logging wiki page](https://github.com/sidekiq/sidekiq/wiki/Logging) for more details.
|
436
509
|
- **BREAKING CHANGE** Validate proper usage of the `REDIS_PROVIDER`
|
437
510
|
variable. This variable is meant to hold the name of the environment
|
438
511
|
variable which contains your Redis URL, so that you can switch Redis
|
@@ -879,7 +952,7 @@ Sidekiq::Queues.clear_all
|
|
879
952
|
- **FIX MEMORY LEAK** Under rare conditions, threads may leak [#2598, gazay]
|
880
953
|
- Add Ukrainian locale [#2561, elrakita]
|
881
954
|
- Disconnect and retry Redis operations if we see a READONLY error [#2550]
|
882
|
-
- Add server middleware testing harness; see [wiki](https://github.com/
|
955
|
+
- Add server middleware testing harness; see [wiki](https://github.com/sidekiq/sidekiq/wiki/Testing#testing-server-middleware) [#2534, ryansch]
|
883
956
|
|
884
957
|
3.5.0
|
885
958
|
-----------
|
@@ -897,7 +970,7 @@ Sidekiq::Queues.clear_all
|
|
897
970
|
- Fix CSRF vulnerability in Web UI, thanks to Egor Homakov for
|
898
971
|
reporting. [#2422] If you are running the Web UI as a standalone Rack app,
|
899
972
|
ensure you have a [session middleware
|
900
|
-
configured](https://github.com/
|
973
|
+
configured](https://github.com/sidekiq/sidekiq/wiki/Monitoring#standalone):
|
901
974
|
```ruby
|
902
975
|
use Rack::Session::Cookie, :secret => "some unique secret string here"
|
903
976
|
```
|
@@ -1281,7 +1354,7 @@ middleware, see docs/3.0-Upgrade.md.**
|
|
1281
1354
|
appear to be doing any work. [#1194]
|
1282
1355
|
- Sidekiq's testing behavior is now dynamic. You can choose between
|
1283
1356
|
`inline` and `fake` behavior in your tests. See
|
1284
|
-
[Testing](https://github.com/
|
1357
|
+
[Testing](https://github.com/sidekiq/sidekiq/wiki/Testing) for detail. [#1193]
|
1285
1358
|
- The Retries table has a new column for the error message.
|
1286
1359
|
- The Web UI topbar now contains the status and live poll button.
|
1287
1360
|
- Orphaned worker records are now auto-vacuumed when you visit the
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@ Sidekiq
|
|
2
2
|
==============
|
3
3
|
|
4
4
|
[![Gem Version](https://badge.fury.io/rb/sidekiq.svg)](https://rubygems.org/gems/sidekiq)
|
5
|
-
![Build](https://github.com/
|
5
|
+
![Build](https://github.com/sidekiq/sidekiq/workflows/CI/badge.svg)
|
6
6
|
|
7
7
|
Simple, efficient background processing for Ruby.
|
8
8
|
|
@@ -10,19 +10,6 @@ Sidekiq uses threads to handle many jobs at the same time in the
|
|
10
10
|
same process. It does not require Rails but will integrate tightly with
|
11
11
|
Rails to make background processing dead simple.
|
12
12
|
|
13
|
-
Performance
|
14
|
-
---------------
|
15
|
-
|
16
|
-
Version | Latency | Garbage created for 10k jobs | Time to process 100k jobs | Throughput | Ruby
|
17
|
-
-----------------|------|---------|---------|------------------------|-----
|
18
|
-
Sidekiq 6.0.2 | 3 ms | 156 MB | 14.0 sec| **7100 jobs/sec** | MRI 2.6.3
|
19
|
-
Sidekiq 6.0.0 | 3 ms | 156 MB | 19 sec | 5200 jobs/sec | MRI 2.6.3
|
20
|
-
Sidekiq 4.0.0 | 10 ms | 151 MB | 22 sec | 4500 jobs/sec |
|
21
|
-
Sidekiq 3.5.1 | 22 ms | 1257 MB | 125 sec | 800 jobs/sec |
|
22
|
-
Resque 1.25.2 | - | - | 420 sec | 240 jobs/sec |
|
23
|
-
DelayedJob 4.1.1 | - | - | 465 sec | 215 jobs/sec |
|
24
|
-
|
25
|
-
This benchmark can be found in `bin/sidekiqload` and assumes a Redis network latency of 1ms.
|
26
13
|
|
27
14
|
Requirements
|
28
15
|
-----------------
|
@@ -42,12 +29,32 @@ Installation
|
|
42
29
|
Getting Started
|
43
30
|
-----------------
|
44
31
|
|
45
|
-
See the [Getting Started wiki page](https://github.com/
|
32
|
+
See the [Getting Started wiki page](https://github.com/sidekiq/sidekiq/wiki/Getting-Started) and follow the simple setup process.
|
46
33
|
You can watch [this YouTube playlist](https://www.youtube.com/playlist?list=PLjeHh2LSCFrWGT5uVjUuFKAcrcj5kSai1) to learn all about
|
47
34
|
Sidekiq and see its features in action. Here's the Web UI:
|
48
35
|
|
49
|
-
![Web UI](https://github.com/
|
36
|
+
![Web UI](https://github.com/sidekiq/sidekiq/raw/main/examples/web-ui.png)
|
37
|
+
|
38
|
+
Performance
|
39
|
+
---------------
|
40
|
+
|
41
|
+
The benchmark in `bin/sidekiqload` creates 500,000 no-op jobs and drains them as fast as possible, assuming a fixed Redis network latency of 1ms.
|
42
|
+
This requires a lot of Redis network I/O and JSON parsing.
|
43
|
+
This benchmark is IO-bound so we increase the concurrency to 25.
|
44
|
+
If your application is sending lots of emails or performing other network-intensive work, you could see a similar benefit but be careful not to saturate the CPU.
|
45
|
+
|
46
|
+
Version | Time to process 500k jobs | Throughput (jobs/sec) | Ruby | Concurrency | Job Type
|
47
|
+
-----------------|------|---------|---------|------------------------|---
|
48
|
+
Sidekiq 7.0.3 | 21.3 sec| 23,500 | 3.2.0+yjit | 30 | Sidekiq::Job
|
49
|
+
Sidekiq 7.0.3 | 33.8 sec| 14,700 | 3.2.0+yjit | 30 | ActiveJob 7.0.4
|
50
|
+
Sidekiq 7.0.3 | 23.5 sec| 21,300 | 3.2.0 | 30 | Sidekiq::Job
|
51
|
+
Sidekiq 7.0.3 | 46.5 sec| 10,700 | 3.2.0 | 30 | ActiveJob 7.0.4
|
52
|
+
Sidekiq 7.0.3 | 23.0 sec| 21,700 | 2.7.5 | 30 | Sidekiq::Job
|
53
|
+
Sidekiq 7.0.3 | 46.5 sec| 10,850 | 2.7.5 | 30 | ActiveJob 7.0.4
|
50
54
|
|
55
|
+
Most of Sidekiq's overhead is Redis network I/O.
|
56
|
+
ActiveJob adds a notable amount of CPU overhead due to argument deserialization and callbacks.
|
57
|
+
Concurrency of 30 was determined experimentally to maximize one CPU without saturating it.
|
51
58
|
|
52
59
|
Want to Upgrade?
|
53
60
|
-------------------
|
@@ -67,15 +74,15 @@ Problems?
|
|
67
74
|
**Please do not directly email any Sidekiq committers with questions or problems.**
|
68
75
|
A community is best served when discussions are held in public.
|
69
76
|
|
70
|
-
If you have a problem, please review the [FAQ](https://github.com/
|
71
|
-
Searching the [issues](https://github.com/
|
77
|
+
If you have a problem, please review the [FAQ](https://github.com/sidekiq/sidekiq/wiki/FAQ) and [Troubleshooting](https://github.com/sidekiq/sidekiq/wiki/Problems-and-Troubleshooting) wiki pages.
|
78
|
+
Searching the [issues](https://github.com/sidekiq/sidekiq/issues) for your problem is also a good idea.
|
72
79
|
|
73
80
|
Sidekiq Pro and Sidekiq Enterprise customers get private email support.
|
74
81
|
You can purchase at https://sidekiq.org; email support@contribsys.com for help.
|
75
82
|
|
76
83
|
Useful resources:
|
77
84
|
|
78
|
-
* Product documentation is in the [wiki](https://github.com/
|
85
|
+
* Product documentation is in the [wiki](https://github.com/sidekiq/sidekiq/wiki).
|
79
86
|
* Occasional announcements are made to the [@sidekiq](https://twitter.com/sidekiq) Twitter account.
|
80
87
|
* The [Sidekiq tag](https://stackoverflow.com/questions/tagged/sidekiq) on Stack Overflow has lots of useful Q & A.
|
81
88
|
|
@@ -85,13 +92,13 @@ See the [Sidekiq support page](https://sidekiq.org/support.html) for details.
|
|
85
92
|
Contributing
|
86
93
|
-----------------
|
87
94
|
|
88
|
-
Please see [the contributing guidelines](https://github.com/
|
95
|
+
Please see [the contributing guidelines](https://github.com/sidekiq/sidekiq/blob/main/.github/contributing.md).
|
89
96
|
|
90
97
|
License
|
91
98
|
-----------------
|
92
99
|
|
93
|
-
Please see [LICENSE.txt](https://github.com/
|
94
|
-
The license for Sidekiq Pro and Sidekiq Enterprise can be found in [COMM-LICENSE.txt](https://github.com/
|
100
|
+
Please see [LICENSE.txt](https://github.com/sidekiq/sidekiq/blob/main/LICENSE.txt) for licensing details.
|
101
|
+
The license for Sidekiq Pro and Sidekiq Enterprise can be found in [COMM-LICENSE.txt](https://github.com/sidekiq/sidekiq/blob/main/COMM-LICENSE.txt).
|
95
102
|
|
96
103
|
Author
|
97
104
|
-----------------
|
data/bin/sidekiqload
CHANGED
@@ -1,21 +1,59 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
+
#
|
4
|
+
# bin/sidekiqload is a helpful script to load test and
|
5
|
+
# performance tune Sidekiq's core. It creates 500,000 no-op
|
6
|
+
# jobs and executes them as fast as possible.
|
7
|
+
# Example Usage:
|
8
|
+
#
|
9
|
+
# > RUBY_YJIT_ENABLE=1 LATENCY=0 THREADS=10 bin/sidekiqload
|
10
|
+
# Result: Done, 500000 jobs in 20.264945 sec, 24673 jobs/sec
|
11
|
+
#
|
12
|
+
# Use LATENCY=1 to get a more real world network setup
|
13
|
+
# but you'll need to setup and start toxiproxy as noted below.
|
14
|
+
#
|
15
|
+
# Use AJ=1 to test ActiveJob instead of plain old Sidekiq::Jobs so
|
16
|
+
# you can see the runtime performance difference between the two APIs.
|
17
|
+
#
|
18
|
+
# None of this script is considered a public API and may change over time.
|
19
|
+
#
|
20
|
+
|
3
21
|
# Quiet some warnings we see when running in warning mode:
|
4
22
|
# RUBYOPT=-w bundle exec sidekiq
|
5
23
|
$TESTING = false
|
24
|
+
puts RUBY_DESCRIPTION
|
25
|
+
puts(%w[THREADS LATENCY AJ PROFILE].map { |x| "#{x}: #{ENV[x] || "nil"}" }.join(", "))
|
6
26
|
|
7
|
-
|
27
|
+
require "ruby-prof" if ENV["PROFILE"]
|
8
28
|
require "bundler/setup"
|
9
29
|
Bundler.require(:default, :load_test)
|
10
30
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
#
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
31
|
+
latency = Integer(ENV["LATENCY"] || 1)
|
32
|
+
if latency > 0
|
33
|
+
# brew tap shopify/shopify
|
34
|
+
# brew install toxiproxy
|
35
|
+
# run `toxiproxy-server` in a separate terminal window.
|
36
|
+
require "toxiproxy"
|
37
|
+
# simulate a non-localhost network for realer-world conditions.
|
38
|
+
# adding 1ms of network latency has an ENORMOUS impact on benchmarks
|
39
|
+
Toxiproxy.populate([{
|
40
|
+
name: "redis",
|
41
|
+
listen: "127.0.0.1:6380",
|
42
|
+
upstream: "127.0.0.1:6379"
|
43
|
+
}])
|
44
|
+
end
|
45
|
+
|
46
|
+
if ENV["AJ"]
|
47
|
+
require "active_job"
|
48
|
+
puts "Using ActiveJob #{ActiveJob::VERSION::STRING}"
|
49
|
+
ActiveJob::Base.queue_adapter = :sidekiq
|
50
|
+
ActiveJob::Base.logger.level = Logger::WARN
|
51
|
+
|
52
|
+
class LoadJob < ActiveJob::Base
|
53
|
+
def perform(idx, ts = nil)
|
54
|
+
puts(Time.now.to_f - ts) if !ts.nil?
|
55
|
+
end
|
56
|
+
end
|
19
57
|
end
|
20
58
|
|
21
59
|
class LoadWorker
|
@@ -31,122 +69,179 @@ class LoadWorker
|
|
31
69
|
end
|
32
70
|
end
|
33
71
|
|
34
|
-
|
35
|
-
|
36
|
-
# run `toxiproxy-server` in a separate terminal window.
|
37
|
-
require "toxiproxy"
|
38
|
-
# simulate a non-localhost network for realer-world conditions.
|
39
|
-
# adding 1ms of network latency has an ENORMOUS impact on benchmarks
|
40
|
-
Toxiproxy.populate([{
|
41
|
-
name: "redis",
|
42
|
-
listen: "127.0.0.1:6380",
|
43
|
-
upstream: "127.0.0.1:6379"
|
44
|
-
}])
|
45
|
-
|
46
|
-
self_read, self_write = IO.pipe
|
47
|
-
%w[INT TERM TSTP TTIN].each do |sig|
|
48
|
-
trap sig do
|
49
|
-
self_write.puts(sig)
|
50
|
-
end
|
51
|
-
rescue ArgumentError
|
52
|
-
puts "Signal #{sig} not supported"
|
72
|
+
def Process.rss
|
73
|
+
`ps -o rss= -p #{Process.pid}`.chomp.to_i
|
53
74
|
end
|
54
75
|
|
55
|
-
|
56
|
-
def
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
+
class Loader
|
77
|
+
def initialize
|
78
|
+
@iter = ENV["GC"] ? 10 : 500
|
79
|
+
@count = Integer(ENV["COUNT"] || 1_000)
|
80
|
+
@latency = Integer(ENV["LATENCY"] || 1)
|
81
|
+
end
|
82
|
+
|
83
|
+
def configure
|
84
|
+
@x = Sidekiq.configure_embed do |config|
|
85
|
+
config.redis = {db: 13, port: ((@latency > 0) ? 6380 : 6379)}
|
86
|
+
config.concurrency = Integer(ENV.fetch("THREADS", "10"))
|
87
|
+
# config.redis = { db: 13, port: 6380, driver: :hiredis}
|
88
|
+
config.queues = %w[default]
|
89
|
+
config.logger.level = Logger::WARN
|
90
|
+
config.average_scheduled_poll_interval = 2
|
91
|
+
config.reliable! if defined?(Sidekiq::Pro)
|
92
|
+
end
|
93
|
+
|
94
|
+
@self_read, @self_write = IO.pipe
|
95
|
+
%w[INT TERM TSTP TTIN].each do |sig|
|
96
|
+
trap sig do
|
97
|
+
@self_write.puts(sig)
|
76
98
|
end
|
99
|
+
rescue ArgumentError
|
100
|
+
puts "Signal #{sig} not supported"
|
77
101
|
end
|
78
102
|
end
|
79
|
-
end
|
80
103
|
|
81
|
-
def
|
82
|
-
|
83
|
-
|
104
|
+
def handle_signal(sig)
|
105
|
+
launcher = @x
|
106
|
+
Sidekiq.logger.debug "Got #{sig} signal"
|
107
|
+
case sig
|
108
|
+
when "INT"
|
109
|
+
# Handle Ctrl-C in JRuby like MRI
|
110
|
+
# http://jira.codehaus.org/browse/JRUBY-4637
|
111
|
+
raise Interrupt
|
112
|
+
when "TERM"
|
113
|
+
# Heroku sends TERM and then waits 30 seconds for process to exit.
|
114
|
+
raise Interrupt
|
115
|
+
when "TSTP"
|
116
|
+
Sidekiq.logger.info "Received TSTP, no longer accepting new work"
|
117
|
+
launcher.quiet
|
118
|
+
when "TTIN"
|
119
|
+
Thread.list.each do |thread|
|
120
|
+
Sidekiq.logger.warn "Thread TID-#{(thread.object_id ^ ::Process.pid).to_s(36)} #{thread["label"]}"
|
121
|
+
if thread.backtrace
|
122
|
+
Sidekiq.logger.warn thread.backtrace.join("\n")
|
123
|
+
else
|
124
|
+
Sidekiq.logger.warn "<no backtrace available>"
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
84
129
|
|
85
|
-
|
86
|
-
|
130
|
+
def setup
|
131
|
+
Sidekiq.logger.error("Setup RSS: #{Process.rss}")
|
132
|
+
Sidekiq.redis { |c| c.flushdb }
|
133
|
+
start = Time.now
|
134
|
+
if ENV["AJ"]
|
135
|
+
@iter.times do
|
136
|
+
@count.times do |idx|
|
137
|
+
LoadJob.perform_later(idx)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
else
|
141
|
+
@iter.times do
|
142
|
+
arr = Array.new(@count) { |idx| [idx] }
|
143
|
+
Sidekiq::Client.push_bulk("class" => LoadWorker, "args" => arr)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
Sidekiq.logger.warn "Created #{@count * @iter} jobs in #{Time.now - start} sec"
|
147
|
+
end
|
87
148
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
149
|
+
def monitor
|
150
|
+
@monitor = Thread.new do
|
151
|
+
GC.start
|
152
|
+
loop do
|
153
|
+
sleep 0.2
|
154
|
+
qsize = Sidekiq.redis do |conn|
|
155
|
+
conn.llen "queue:default"
|
156
|
+
end
|
157
|
+
total = qsize
|
158
|
+
if total == 0
|
159
|
+
ending = Time.now - @start
|
160
|
+
size = @iter * @count
|
161
|
+
Sidekiq.logger.error("Done, #{size} jobs in #{ending} sec, #{(size / ending).to_i} jobs/sec")
|
162
|
+
Sidekiq.logger.error("Ending RSS: #{Process.rss}")
|
163
|
+
Sidekiq.logger.error("Now here's the latency for three jobs")
|
164
|
+
|
165
|
+
if ENV["AJ"]
|
166
|
+
LoadJob.perform_later(1, Time.now.to_f)
|
167
|
+
LoadJob.perform_later(2, Time.now.to_f)
|
168
|
+
LoadJob.perform_later(3, Time.now.to_f)
|
169
|
+
else
|
170
|
+
LoadWorker.perform_async(1, Time.now.to_f)
|
171
|
+
LoadWorker.perform_async(2, Time.now.to_f)
|
172
|
+
LoadWorker.perform_async(3, Time.now.to_f)
|
173
|
+
end
|
174
|
+
|
175
|
+
sleep 0.1
|
176
|
+
@x.stop
|
177
|
+
Process.kill("INT", $$)
|
178
|
+
break
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
93
183
|
|
94
|
-
|
184
|
+
def with_latency(latency, &block)
|
185
|
+
Sidekiq.logger.error "Simulating #{latency}ms of latency between Sidekiq and redis"
|
186
|
+
if latency > 0
|
187
|
+
Toxiproxy[:redis].downstream(:latency, latency: latency).apply(&block)
|
188
|
+
else
|
189
|
+
yield
|
190
|
+
end
|
191
|
+
end
|
95
192
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
193
|
+
def run(name)
|
194
|
+
Sidekiq.logger.warn("Starting #{name}")
|
195
|
+
monitor
|
196
|
+
|
197
|
+
if ENV["PROFILE"]
|
198
|
+
RubyProf.exclude_threads = [@monitor]
|
199
|
+
RubyProf.start
|
200
|
+
elsif ENV["GC"]
|
201
|
+
GC.start
|
202
|
+
GC.compact
|
203
|
+
GC.disable
|
204
|
+
Sidekiq.logger.error("GC Start RSS: #{Process.rss}")
|
101
205
|
end
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
LoadWorker.perform_async(3, Time.now.to_f)
|
111
|
-
|
112
|
-
sleep 0.2
|
113
|
-
exit(0)
|
206
|
+
@start = Time.now
|
207
|
+
with_latency(@latency) do
|
208
|
+
@x.run
|
209
|
+
|
210
|
+
while (readable_io = IO.select([@self_read]))
|
211
|
+
signal = readable_io.first[0].gets.strip
|
212
|
+
handle_signal(signal)
|
213
|
+
end
|
114
214
|
end
|
215
|
+
# normal
|
216
|
+
rescue Interrupt
|
217
|
+
rescue => e
|
218
|
+
raise e if $DEBUG
|
219
|
+
warn e.message
|
220
|
+
warn e.backtrace.join("\n")
|
221
|
+
exit 1
|
222
|
+
ensure
|
223
|
+
@x.stop
|
115
224
|
end
|
116
|
-
end
|
117
225
|
|
118
|
-
def
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
226
|
+
def done
|
227
|
+
Sidekiq.logger.error("GC End RSS: #{Process.rss}") if ENV["GC"]
|
228
|
+
if ENV["PROFILE"]
|
229
|
+
Sidekiq.logger.error("Profiling...")
|
230
|
+
result = RubyProf.stop
|
231
|
+
printer = RubyProf::GraphHtmlPrinter.new(result)
|
232
|
+
printer.print(File.new("output.html", "w"), min_percent: 1)
|
233
|
+
end
|
124
234
|
end
|
125
235
|
end
|
126
236
|
|
127
|
-
|
128
|
-
|
129
|
-
# RubyProf.start
|
237
|
+
ll = Loader.new
|
238
|
+
ll.configure
|
130
239
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
while (readable_io = IO.select([self_read]))
|
135
|
-
signal = readable_io.first[0].gets.strip
|
136
|
-
handle_signal(x, signal)
|
137
|
-
end
|
138
|
-
end
|
139
|
-
rescue SystemExit
|
140
|
-
# Sidekiq.logger.error("Profiling...")
|
141
|
-
# result = RubyProf.stop
|
142
|
-
# printer = RubyProf::GraphHtmlPrinter.new(result)
|
143
|
-
# printer.print(File.new("output.html", "w"), min_percent: 1)
|
144
|
-
# normal
|
145
|
-
rescue => e
|
146
|
-
raise e if $DEBUG
|
147
|
-
warn e.message
|
148
|
-
warn e.backtrace.join("\n")
|
149
|
-
exit 1
|
150
|
-
ensure
|
151
|
-
x.stop
|
240
|
+
if ENV["WARM"]
|
241
|
+
ll.setup
|
242
|
+
ll.run("warmup")
|
152
243
|
end
|
244
|
+
|
245
|
+
ll.setup
|
246
|
+
ll.run("load")
|
247
|
+
ll.done
|