sidekiq 7.0.1 → 7.0.8

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.

Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/Changes.md +69 -9
  3. data/README.md +29 -22
  4. data/bin/sidekiqload +186 -109
  5. data/bin/sidekiqmon +3 -0
  6. data/lib/sidekiq/api.rb +43 -4
  7. data/lib/sidekiq/capsule.rb +17 -0
  8. data/lib/sidekiq/cli.rb +3 -2
  9. data/lib/sidekiq/client.rb +1 -1
  10. data/lib/sidekiq/component.rb +2 -0
  11. data/lib/sidekiq/config.rb +2 -3
  12. data/lib/sidekiq/deploy.rb +3 -3
  13. data/lib/sidekiq/embedded.rb +1 -1
  14. data/lib/sidekiq/fetch.rb +3 -5
  15. data/lib/sidekiq/job.rb +2 -2
  16. data/lib/sidekiq/job_logger.rb +1 -1
  17. data/lib/sidekiq/job_retry.rb +5 -4
  18. data/lib/sidekiq/job_util.rb +48 -14
  19. data/lib/sidekiq/launcher.rb +13 -7
  20. data/lib/sidekiq/metrics/query.rb +1 -1
  21. data/lib/sidekiq/metrics/tracking.rb +2 -0
  22. data/lib/sidekiq/middleware/chain.rb +12 -9
  23. data/lib/sidekiq/middleware/current_attributes.rb +5 -7
  24. data/lib/sidekiq/monitor.rb +17 -4
  25. data/lib/sidekiq/paginator.rb +2 -2
  26. data/lib/sidekiq/processor.rb +4 -1
  27. data/lib/sidekiq/rails.rb +2 -1
  28. data/lib/sidekiq/redis_client_adapter.rb +3 -6
  29. data/lib/sidekiq/scheduled.rb +1 -1
  30. data/lib/sidekiq/version.rb +1 -1
  31. data/lib/sidekiq/web/application.rb +20 -5
  32. data/lib/sidekiq/web/helpers.rb +15 -7
  33. data/lib/sidekiq/web.rb +4 -0
  34. data/sidekiq.gemspec +11 -22
  35. data/web/assets/javascripts/application.js +18 -0
  36. data/web/assets/javascripts/metrics.js +30 -2
  37. data/web/assets/stylesheets/application-dark.css +4 -0
  38. data/web/assets/stylesheets/application.css +3 -3
  39. data/web/locales/da.yml +11 -4
  40. data/web/locales/ja.yml +3 -1
  41. data/web/views/_footer.erb +2 -2
  42. data/web/views/_job_info.erb +18 -2
  43. data/web/views/_metrics_period_select.erb +12 -0
  44. data/web/views/_paging.erb +2 -0
  45. data/web/views/busy.erb +37 -26
  46. data/web/views/metrics.erb +6 -4
  47. data/web/views/metrics_for_job.erb +9 -7
  48. data/web/views/morgue.erb +5 -9
  49. data/web/views/queue.erb +10 -14
  50. data/web/views/queues.erb +3 -1
  51. data/web/views/retries.erb +5 -9
  52. data/web/views/scheduled.erb +12 -13
  53. metadata +17 -26
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 98aab60f0a9bd14122cf62b2f31c17e41b67feb8c9fb13865ef0a16002d38ed7
4
- data.tar.gz: 94038f0176ccb7785c6112cd41e915e4a1c7f66298a9670457a68e6b62f2710c
3
+ metadata.gz: 69b692f7976998a1655a5c6f108c0a1f686fdcdcde164f6cde071f9ea3f89ced
4
+ data.tar.gz: d78d581fa48b744789b3af117a55d71bab1037b592f58ee9c74cf2c132716e0c
5
5
  SHA512:
6
- metadata.gz: c41c724dc99aa3fdf49db46eeac0bec822bd6a67989792f4830900da7b74882c27837535a03a2ea6ed0575736fc895b23bb3440613d1f581e877bcbfe1c06934
7
- data.tar.gz: 482af09f25f72f9fa0261f02e4e224dc58a400519f167f8cb0ea0dda4960b24a41b105731a4fcc2b81ff15f158497b9bf1cc86d55272ed8fe4ca7ed9029bc047
6
+ metadata.gz: 42d16710f20a67a94df6498cf1fb5097a8795a5611f058e58d60e43e82503d26871c6d3061b3404590a0e0eba319997cb7e1daec3a88b66c2356e9cc0164a781
7
+ data.tar.gz: 5b6d9aa7512a67cb552c3a1bed37aa111a877927e7690f53efd3e85aa1ea7049fb75eb05b31232810c8a805f95cb0959a54cc80bafb5c80f9aae0c0701d158b7
data/Changes.md CHANGED
@@ -1,6 +1,66 @@
1
1
  # Sidekiq Changes
2
2
 
3
- [Sidekiq Changes](https://github.com/mperham/sidekiq/blob/main/Changes.md) | [Sidekiq Pro Changes](https://github.com/mperham/sidekiq/blob/main/Pro-Changes.md) | [Sidekiq Enterprise Changes](https://github.com/mperham/sidekiq/blob/main/Ent-Changes.md)
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.0.8
6
+ ----------
7
+
8
+ - **SECURITY** Sanitize `period` input parameter on Metrics pages.
9
+ Specially crafted values can lead to XSS. This functionality
10
+ was introduced in 7.0.4. Thank you to spercex @ huntr.dev [#5694]
11
+ - Add job hash as 3rd parameter to the `sidekiq_retry_in` block.
12
+
13
+ 7.0.7
14
+ ----------
15
+
16
+ - Fix redis-client API usage which could result in stuck Redis
17
+ connections [#5823]
18
+ - Fix AS::Duration with `sidekiq_retry_in` [#5806]
19
+ - Restore dumping config options on startup with `-v` [#5822]
20
+
21
+ 7.0.5,7.0.6
22
+ ----------
23
+
24
+ - More context for debugging json unsafe errors [#5787]
25
+
26
+ 7.0.4
27
+ ----------
28
+
29
+ - Performance and memory optimizations [#5768, fatkodima]
30
+ - Add 1-8 hour period selector to Metrics pages [#5694]
31
+ - Fix process display with `sidekiqmon` [#5733]
32
+
33
+ 7.0.3
34
+ ----------
35
+
36
+ - Don't warn about memory policy on Redis Enterprise [#5712]
37
+ - Don't allow Quiet/Stop on embedded Sidekiq instances [#5716]
38
+ - Fix `size: X` for configuring the default Redis pool size [#5702]
39
+ - Improve the display of queue weights on Busy page [#5642]
40
+ - Freeze CurrentAttributes on a job once initially set [#5692]
41
+
42
+ 7.0.2
43
+ ----------
44
+
45
+ - Improve compatibility with custom loggers [#5673]
46
+ - Add queue weights on Busy page [#5640]
47
+ - Add BID link on job_info page if job is part of a Batch [#5623]
48
+ - Allow custom extensions to add rows/links within Job detail pages [#5624]
49
+ ```ruby
50
+ Sidekiq::Web.custom_job_info_rows << AddAccountLink.new
51
+
52
+ class AddAccountLink
53
+ include CGI::Util
54
+ def add_pair(job)
55
+ # yield a (name, value) pair
56
+ # You can include HTML tags and CSS, Sidekiq does not do any
57
+ # escaping so beware user data injection! Note how we use CGI's
58
+ # `h` escape helper.
59
+ aid = job["account_id"]
60
+ yield "Account", "<a href='/accounts/#{h aid}'>#{h aid}</a>" if aid
61
+ end
62
+ end
63
+ ```
4
64
 
5
65
  7.0.1
6
66
  ----------
@@ -56,7 +116,7 @@
56
116
  6.5.2
57
117
  ----------
58
118
 
59
- - [Job Metrics are under active development, help wanted!](https://github.com/mperham/sidekiq/wiki/Metrics#contributing) **BETA**
119
+ - [Job Metrics are under active development, help wanted!](https://github.com/sidekiq/sidekiq/wiki/Metrics#contributing) **BETA**
60
120
  - Add `Context` column on queue page which shows any CurrentAttributes [#5450]
61
121
  - `sidekiq_retry_in` may now return `:discard` or `:kill` to dynamically stop job retries [#5406]
62
122
  - Smarter sorting of processes in /busy Web UI [#5398]
@@ -75,7 +135,7 @@
75
135
  - Substantial refactoring of Sidekiq server internals, part of a larger effort
76
136
  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).
77
137
  - **Add beta support for the `redis-client` gem**. This will become the default Redis driver in Sidekiq 7.0. [#5298]
78
- Read more: https://github.com/mperham/sidekiq/wiki/Using-redis-client
138
+ Read more: https://github.com/sidekiq/sidekiq/wiki/Using-redis-client
79
139
  - **Add beta support for DB transaction-aware client** [#5291]
80
140
  Add this line to your initializer and any jobs created during a transaction
81
141
  will only be pushed to Redis **after the transaction commits**. You will need to add the
@@ -275,7 +335,7 @@ If this is a Rails app in API mode, you need to enable sessions.
275
335
  ---------
276
336
 
277
337
  - **Integrate with systemd's watchdog and notification features** [#4488]
278
- Set `Type=notify` in [sidekiq.service](https://github.com/mperham/sidekiq/blob/4b8a8bd3ae42f6e48ae1fdaf95ed7d7af18ed8bb/examples/systemd/sidekiq.service#L30-L39). The integration works automatically.
338
+ Set `Type=notify` in [sidekiq.service](https://github.com/sidekiq/sidekiq/blob/4b8a8bd3ae42f6e48ae1fdaf95ed7d7af18ed8bb/examples/systemd/sidekiq.service#L30-L39). The integration works automatically.
279
339
  - Use `setTimeout` rather than `setInterval` to avoid thundering herd [#4480]
280
340
  - Fix edge case where a job can be pushed without a queue.
281
341
  - Flush job stats at exit [#4498]
@@ -288,7 +348,7 @@ If this is a Rails app in API mode, you need to enable sessions.
288
348
  - Fix broken Web UI response when using NewRelic and Rack 2.1.2+. [#4440]
289
349
  - Update APIs to use `UNLINK`, not `DEL`. [#4449]
290
350
  - Fix Ruby 2.7 warnings [#4412]
291
- - Add support for `APP_ENV` [[95fa5d9]](https://github.com/mperham/sidekiq/commit/95fa5d90192148026e52ca2902f1b83c70858ce8)
351
+ - Add support for `APP_ENV` [[95fa5d9]](https://github.com/sidekiq/sidekiq/commit/95fa5d90192148026e52ca2902f1b83c70858ce8)
292
352
 
293
353
  6.0.4
294
354
  ---------
@@ -400,7 +460,7 @@ Sidekiq.configure_server do |config|
400
460
  config.log_formatter = Sidekiq::Logger::Formatters::JSON.new
401
461
  end
402
462
  ```
403
- See the [Logging wiki page](https://github.com/mperham/sidekiq/wiki/Logging) for more details.
463
+ See the [Logging wiki page](https://github.com/sidekiq/sidekiq/wiki/Logging) for more details.
404
464
  - **BREAKING CHANGE** Validate proper usage of the `REDIS_PROVIDER`
405
465
  variable. This variable is meant to hold the name of the environment
406
466
  variable which contains your Redis URL, so that you can switch Redis
@@ -847,7 +907,7 @@ Sidekiq::Queues.clear_all
847
907
  - **FIX MEMORY LEAK** Under rare conditions, threads may leak [#2598, gazay]
848
908
  - Add Ukrainian locale [#2561, elrakita]
849
909
  - Disconnect and retry Redis operations if we see a READONLY error [#2550]
850
- - Add server middleware testing harness; see [wiki](https://github.com/mperham/sidekiq/wiki/Testing#testing-server-middleware) [#2534, ryansch]
910
+ - Add server middleware testing harness; see [wiki](https://github.com/sidekiq/sidekiq/wiki/Testing#testing-server-middleware) [#2534, ryansch]
851
911
 
852
912
  3.5.0
853
913
  -----------
@@ -865,7 +925,7 @@ Sidekiq::Queues.clear_all
865
925
  - Fix CSRF vulnerability in Web UI, thanks to Egor Homakov for
866
926
  reporting. [#2422] If you are running the Web UI as a standalone Rack app,
867
927
  ensure you have a [session middleware
868
- configured](https://github.com/mperham/sidekiq/wiki/Monitoring#standalone):
928
+ configured](https://github.com/sidekiq/sidekiq/wiki/Monitoring#standalone):
869
929
  ```ruby
870
930
  use Rack::Session::Cookie, :secret => "some unique secret string here"
871
931
  ```
@@ -1249,7 +1309,7 @@ middleware, see docs/3.0-Upgrade.md.**
1249
1309
  appear to be doing any work. [#1194]
1250
1310
  - Sidekiq's testing behavior is now dynamic. You can choose between
1251
1311
  `inline` and `fake` behavior in your tests. See
1252
- [Testing](https://github.com/mperham/sidekiq/wiki/Testing) for detail. [#1193]
1312
+ [Testing](https://github.com/sidekiq/sidekiq/wiki/Testing) for detail. [#1193]
1253
1313
  - The Retries table has a new column for the error message.
1254
1314
  - The Web UI topbar now contains the status and live poll button.
1255
1315
  - 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/mperham/sidekiq/workflows/CI/badge.svg)
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/mperham/sidekiq/wiki/Getting-Started) and follow the simple setup process.
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/mperham/sidekiq/raw/main/examples/web-ui.png)
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/mperham/sidekiq/wiki/FAQ) and [Troubleshooting](https://github.com/mperham/sidekiq/wiki/Problems-and-Troubleshooting) wiki pages.
71
- Searching the [issues](https://github.com/mperham/sidekiq/issues) for your problem is also a good idea.
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/mperham/sidekiq/wiki).
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 &amp; 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/mperham/sidekiq/blob/main/.github/contributing.md).
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/mperham/sidekiq/blob/main/LICENSE.txt) for licensing details.
94
- The license for Sidekiq Pro and Sidekiq Enterprise can be found in [COMM-LICENSE.txt](https://github.com/mperham/sidekiq/blob/main/COMM-LICENSE.txt).
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
@@ -3,19 +3,39 @@
3
3
  # Quiet some warnings we see when running in warning mode:
4
4
  # RUBYOPT=-w bundle exec sidekiq
5
5
  $TESTING = false
6
+ puts RUBY_DESCRIPTION
7
+ puts(%w[THREADS LATENCY AJ PROFILE].map { |x| "#{x}: #{ENV[x] || "nil"}" }.join(", "))
6
8
 
7
- # require "ruby-prof"
9
+ require "ruby-prof" if ENV["PROFILE"]
8
10
  require "bundler/setup"
9
11
  Bundler.require(:default, :load_test)
10
12
 
11
- x = Sidekiq.configure_embed do |config|
12
- config.redis = {db: 13, port: 6380}
13
- config.concurrency = 10
14
- # config.redis = { db: 13, port: 6380, driver: :hiredis}
15
- config.queues = %w[default]
16
- config.logger.level = Logger::ERROR
17
- config.average_scheduled_poll_interval = 2
18
- config.reliable! if defined?(Sidekiq::Pro)
13
+ latency = Integer(ENV["LATENCY"] || 1)
14
+ if latency > 0
15
+ # brew tap shopify/shopify
16
+ # brew install toxiproxy
17
+ # run `toxiproxy-server` in a separate terminal window.
18
+ require "toxiproxy"
19
+ # simulate a non-localhost network for realer-world conditions.
20
+ # adding 1ms of network latency has an ENORMOUS impact on benchmarks
21
+ Toxiproxy.populate([{
22
+ name: "redis",
23
+ listen: "127.0.0.1:6380",
24
+ upstream: "127.0.0.1:6379"
25
+ }])
26
+ end
27
+
28
+ if ENV["AJ"]
29
+ require "active_job"
30
+ puts "Using ActiveJob #{ActiveJob::VERSION::STRING}"
31
+ ActiveJob::Base.queue_adapter = :sidekiq
32
+ ActiveJob::Base.logger.level = Logger::WARN
33
+
34
+ class LoadJob < ActiveJob::Base
35
+ def perform(idx, ts=nil)
36
+ puts(Time.now.to_f - ts) if !ts.nil?
37
+ end
38
+ end
19
39
  end
20
40
 
21
41
  class LoadWorker
@@ -31,122 +51,179 @@ class LoadWorker
31
51
  end
32
52
  end
33
53
 
34
- # brew tap shopify/shopify
35
- # brew install toxiproxy
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"
54
+ def Process.rss
55
+ `ps -o rss= -p #{Process.pid}`.chomp.to_i
53
56
  end
54
57
 
55
- Sidekiq.redis { |c| c.flushdb }
56
- def handle_signal(launcher, sig)
57
- Sidekiq.logger.debug "Got #{sig} signal"
58
- case sig
59
- when "INT"
60
- # Handle Ctrl-C in JRuby like MRI
61
- # http://jira.codehaus.org/browse/JRUBY-4637
62
- raise Interrupt
63
- when "TERM"
64
- # Heroku sends TERM and then waits 30 seconds for process to exit.
65
- raise Interrupt
66
- when "TSTP"
67
- Sidekiq.logger.info "Received TSTP, no longer accepting new work"
68
- launcher.quiet
69
- when "TTIN"
70
- Thread.list.each do |thread|
71
- Sidekiq.logger.warn "Thread TID-#{(thread.object_id ^ ::Process.pid).to_s(36)} #{thread["label"]}"
72
- if thread.backtrace
73
- Sidekiq.logger.warn thread.backtrace.join("\n")
74
- else
75
- Sidekiq.logger.warn "<no backtrace available>"
58
+ class Loader
59
+ def initialize
60
+ @iter = ENV["GC"] ? 10 : 500
61
+ @count = Integer(ENV["COUNT"] || 1_000)
62
+ @latency = Integer(ENV["LATENCY"] || 1)
63
+ end
64
+
65
+ def configure
66
+ @x = Sidekiq.configure_embed do |config|
67
+ config.redis = {db: 13, port: ((@latency > 0) ? 6380 : 6379)}
68
+ config.concurrency = Integer(ENV.fetch("THREADS", "10"))
69
+ # config.redis = { db: 13, port: 6380, driver: :hiredis}
70
+ config.queues = %w[default]
71
+ config.logger.level = Logger::WARN
72
+ config.average_scheduled_poll_interval = 2
73
+ config.reliable! if defined?(Sidekiq::Pro)
74
+ end
75
+
76
+ @self_read, @self_write = IO.pipe
77
+ %w[INT TERM TSTP TTIN].each do |sig|
78
+ trap sig do
79
+ @self_write.puts(sig)
76
80
  end
81
+ rescue ArgumentError
82
+ puts "Signal #{sig} not supported"
77
83
  end
78
84
  end
79
- end
80
85
 
81
- def Process.rss
82
- `ps -o rss= -p #{Process.pid}`.chomp.to_i
83
- end
86
+ def handle_signal(sig)
87
+ launcher = @x
88
+ Sidekiq.logger.debug "Got #{sig} signal"
89
+ case sig
90
+ when "INT"
91
+ # Handle Ctrl-C in JRuby like MRI
92
+ # http://jira.codehaus.org/browse/JRUBY-4637
93
+ raise Interrupt
94
+ when "TERM"
95
+ # Heroku sends TERM and then waits 30 seconds for process to exit.
96
+ raise Interrupt
97
+ when "TSTP"
98
+ Sidekiq.logger.info "Received TSTP, no longer accepting new work"
99
+ launcher.quiet
100
+ when "TTIN"
101
+ Thread.list.each do |thread|
102
+ Sidekiq.logger.warn "Thread TID-#{(thread.object_id ^ ::Process.pid).to_s(36)} #{thread["label"]}"
103
+ if thread.backtrace
104
+ Sidekiq.logger.warn thread.backtrace.join("\n")
105
+ else
106
+ Sidekiq.logger.warn "<no backtrace available>"
107
+ end
108
+ end
109
+ end
110
+ end
84
111
 
85
- iter = 10
86
- count = 10_000
112
+ def setup
113
+ Sidekiq.logger.error("Setup RSS: #{Process.rss}")
114
+ Sidekiq.redis { |c| c.flushdb }
115
+ start = Time.now
116
+ if ENV["AJ"]
117
+ @iter.times do
118
+ @count.times do |idx|
119
+ LoadJob.perform_later(idx)
120
+ end
121
+ end
122
+ else
123
+ @iter.times do
124
+ arr = Array.new(@count) { |idx| [idx] }
125
+ Sidekiq::Client.push_bulk("class" => LoadWorker, "args" => arr)
126
+ end
127
+ end
128
+ Sidekiq.logger.warn "Created #{@count * @iter} jobs in #{Time.now - start} sec"
129
+ end
87
130
 
88
- iter.times do
89
- arr = Array.new(count) { |idx| [idx] }
90
- Sidekiq::Client.push_bulk("class" => LoadWorker, "args" => arr)
91
- end
92
- Sidekiq.logger.error "Created #{count * iter} jobs"
131
+ def monitor
132
+ @monitor = Thread.new do
133
+ GC.start
134
+ loop do
135
+ sleep 0.2
136
+ qsize = Sidekiq.redis do |conn|
137
+ conn.llen "queue:default"
138
+ end
139
+ total = qsize
140
+ if total == 0
141
+ ending = Time.now - @start
142
+ size = @iter * @count
143
+ Sidekiq.logger.error("Done, #{size} jobs in #{ending} sec, #{(size / ending).to_i} jobs/sec")
144
+ Sidekiq.logger.error("Ending RSS: #{Process.rss}")
145
+ Sidekiq.logger.error("Now here's the latency for three jobs")
146
+
147
+ if ENV["AJ"]
148
+ LoadJob.perform_later(1, Time.now.to_f)
149
+ LoadJob.perform_later(2, Time.now.to_f)
150
+ LoadJob.perform_later(3, Time.now.to_f)
151
+ else
152
+ LoadWorker.perform_async(1, Time.now.to_f)
153
+ LoadWorker.perform_async(2, Time.now.to_f)
154
+ LoadWorker.perform_async(3, Time.now.to_f)
155
+ end
156
+
157
+ sleep 0.1
158
+ @x.stop
159
+ Process.kill("INT", $$)
160
+ break
161
+ end
162
+ end
163
+ end
164
+ end
93
165
 
94
- start = Time.now
166
+ def with_latency(latency, &block)
167
+ Sidekiq.logger.error "Simulating #{latency}ms of latency between Sidekiq and redis"
168
+ if latency > 0
169
+ Toxiproxy[:redis].downstream(:latency, latency: latency).apply(&block)
170
+ else
171
+ yield
172
+ end
173
+ end
95
174
 
96
- Monitoring = Thread.new do
97
- loop do
98
- sleep 1.0
99
- qsize = Sidekiq.redis do |conn|
100
- conn.llen "queue:default"
175
+ def run(name)
176
+ Sidekiq.logger.warn("Starting #{name}")
177
+ monitor
178
+
179
+ if ENV["PROFILE"]
180
+ RubyProf.exclude_threads = [@monitor]
181
+ RubyProf.start
182
+ elsif ENV["GC"]
183
+ GC.start
184
+ GC.compact
185
+ GC.disable
186
+ Sidekiq.logger.error("GC Start RSS: #{Process.rss}")
101
187
  end
102
- total = qsize
103
- # Sidekiq.logger.error("RSS: #{Process.rss} Pending: #{total}")
104
- if total == 0
105
- Sidekiq.logger.error("Done, #{iter * count} jobs in #{Time.now - start} sec")
106
- Sidekiq.logger.error("Now here's the latency for three jobs")
107
-
108
- LoadWorker.perform_async(1, Time.now.to_f)
109
- LoadWorker.perform_async(2, Time.now.to_f)
110
- LoadWorker.perform_async(3, Time.now.to_f)
111
-
112
- sleep 0.2
113
- exit(0)
188
+ @start = Time.now
189
+ with_latency(@latency) do
190
+ @x.run
191
+
192
+ while (readable_io = IO.select([@self_read]))
193
+ signal = readable_io.first[0].gets.strip
194
+ handle_signal(signal)
195
+ end
114
196
  end
197
+ # normal
198
+ rescue Interrupt
199
+ rescue => e
200
+ raise e if $DEBUG
201
+ warn e.message
202
+ warn e.backtrace.join("\n")
203
+ exit 1
204
+ ensure
205
+ @x.stop
115
206
  end
116
- end
117
207
 
118
- def with_latency(latency, &block)
119
- Sidekiq.logger.error "Simulating #{latency}ms of latency between Sidekiq and redis"
120
- if latency > 0
121
- Toxiproxy[:redis].downstream(:latency, latency: latency).apply(&block)
122
- else
123
- yield
208
+ def done
209
+ Sidekiq.logger.error("GC End RSS: #{Process.rss}") if ENV["GC"]
210
+ if ENV["PROFILE"]
211
+ Sidekiq.logger.error("Profiling...")
212
+ result = RubyProf.stop
213
+ printer = RubyProf::GraphHtmlPrinter.new(result)
214
+ printer.print(File.new("output.html", "w"), min_percent: 1)
215
+ end
124
216
  end
125
217
  end
126
218
 
127
- begin
128
- # RubyProf.exclude_threads = [Monitoring]
129
- # RubyProf.start
219
+ ll = Loader.new
220
+ ll.configure
130
221
 
131
- with_latency(Integer(ENV.fetch("LATENCY", "1"))) do
132
- x.run
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
222
+ unless ENV["GC"] || ENV["PROFILE"]
223
+ ll.setup
224
+ ll.run("warmup")
152
225
  end
226
+
227
+ ll.setup
228
+ ll.run("ideal")
229
+ ll.done
data/bin/sidekiqmon CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  require "sidekiq/monitor"
4
4
 
5
+ # disable the Redis connection pool logging
6
+ Sidekiq.default_configuration.logger.level = :warn
7
+
5
8
  section = "all"
6
9
  section = ARGV[0] if ARGV.size == 1
7
10