sidekiq 7.0.2 → 7.0.5
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.
Potentially problematic release.
This version of sidekiq might be problematic. Click here for more details.
- checksums.yaml +4 -4
 - data/Changes.md +30 -9
 - data/README.md +29 -22
 - data/bin/sidekiqload +186 -109
 - data/bin/sidekiqmon +3 -0
 - data/lib/sidekiq/api.rb +31 -4
 - data/lib/sidekiq/capsule.rb +17 -0
 - data/lib/sidekiq/cli.rb +3 -2
 - data/lib/sidekiq/component.rb +2 -0
 - data/lib/sidekiq/config.rb +1 -1
 - data/lib/sidekiq/embedded.rb +1 -1
 - data/lib/sidekiq/fetch.rb +2 -4
 - data/lib/sidekiq/job_retry.rb +1 -1
 - data/lib/sidekiq/job_util.rb +61 -13
 - data/lib/sidekiq/launcher.rb +10 -7
 - data/lib/sidekiq/metrics/tracking.rb +2 -0
 - data/lib/sidekiq/middleware/chain.rb +12 -9
 - data/lib/sidekiq/middleware/current_attributes.rb +5 -7
 - data/lib/sidekiq/monitor.rb +1 -3
 - data/lib/sidekiq/processor.rb +4 -1
 - data/lib/sidekiq/rails.rb +2 -1
 - data/lib/sidekiq/version.rb +1 -1
 - data/lib/sidekiq/web/application.rb +20 -5
 - data/lib/sidekiq/web/helpers.rb +10 -2
 - data/sidekiq.gemspec +9 -21
 - 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/views/_footer.erb +2 -2
 - data/web/views/_job_info.erb +2 -2
 - data/web/views/_metrics_period_select.erb +12 -0
 - data/web/views/_paging.erb +2 -0
 - data/web/views/busy.erb +24 -26
 - data/web/views/metrics.erb +6 -4
 - data/web/views/metrics_for_job.erb +9 -7
 - data/web/views/morgue.erb +4 -8
 - data/web/views/queue.erb +10 -14
 - data/web/views/queues.erb +3 -1
 - data/web/views/retries.erb +4 -8
 - data/web/views/scheduled.erb +12 -13
 - metadata +14 -24
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: fec40f38a40f555d39f3826d0b2b26dd72d500a8e58a35ff2e85436ad5abb2c7
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: b6b0fde1518951d5715484a046e0732224f819b6c45dba1e18c02e8292b97f55
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: c6e0d60356029b73764a1e57e3e6e570fa8e56758da14f6a16945f502f694d182f71e34b246eed4aaa022b184214f7da8253292deeb3b7540bcf14030b3a1139
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 3b03e4b1373288faceaee25ac08e73da00f3923bbbfd925b5b02dc0af6ec0c37fb7d23a14b6ec90be268df0441b974e100aa07462586b41648126d3b4020460a
         
     | 
    
        data/Changes.md
    CHANGED
    
    | 
         @@ -1,6 +1,27 @@ 
     | 
|
| 
       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.0.5
         
     | 
| 
      
 6 
     | 
    
         
            +
            ----------
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            - More context for debugging json unsafe errors [#5787]
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
            7.0.4
         
     | 
| 
      
 11 
     | 
    
         
            +
            ----------
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            - Performance and memory optimizations [#5768, fatkodima]
         
     | 
| 
      
 14 
     | 
    
         
            +
            - Add 1-8 hour period selector to Metrics pages [#5694]
         
     | 
| 
      
 15 
     | 
    
         
            +
            - Fix process display with `sidekiqmon` [#5733]
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
            7.0.3
         
     | 
| 
      
 18 
     | 
    
         
            +
            ----------
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
            - Don't warn about memory policy on Redis Enterprise [#5712]
         
     | 
| 
      
 21 
     | 
    
         
            +
            - Don't allow Quiet/Stop on embedded Sidekiq instances [#5716]
         
     | 
| 
      
 22 
     | 
    
         
            +
            - Fix `size: X` for configuring the default Redis pool size [#5702]
         
     | 
| 
      
 23 
     | 
    
         
            +
            - Improve the display of queue weights on Busy page [#5642]
         
     | 
| 
      
 24 
     | 
    
         
            +
            - Freeze CurrentAttributes on a job once initially set [#5692]
         
     | 
| 
       4 
25 
     | 
    
         | 
| 
       5 
26 
     | 
    
         
             
            7.0.2
         
     | 
| 
       6 
27 
     | 
    
         
             
            ----------
         
     | 
| 
         @@ -79,7 +100,7 @@ end 
     | 
|
| 
       79 
100 
     | 
    
         
             
            6.5.2
         
     | 
| 
       80 
101 
     | 
    
         
             
            ----------
         
     | 
| 
       81 
102 
     | 
    
         | 
| 
       82 
     | 
    
         
            -
            - [Job Metrics are under active development, help wanted!](https://github.com/ 
     | 
| 
      
 103 
     | 
    
         
            +
            - [Job Metrics are under active development, help wanted!](https://github.com/sidekiq/sidekiq/wiki/Metrics#contributing) **BETA**
         
     | 
| 
       83 
104 
     | 
    
         
             
            - Add `Context` column on queue page which shows any CurrentAttributes [#5450]
         
     | 
| 
       84 
105 
     | 
    
         
             
            - `sidekiq_retry_in` may now return `:discard` or `:kill` to dynamically stop job retries [#5406]
         
     | 
| 
       85 
106 
     | 
    
         
             
            - Smarter sorting of processes in /busy Web UI [#5398]
         
     | 
| 
         @@ -98,7 +119,7 @@ end 
     | 
|
| 
       98 
119 
     | 
    
         
             
            - Substantial refactoring of Sidekiq server internals, part of a larger effort
         
     | 
| 
       99 
120 
     | 
    
         
             
              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).
         
     | 
| 
       100 
121 
     | 
    
         
             
            - **Add beta support for the `redis-client` gem**. This will become the default Redis driver in Sidekiq 7.0. [#5298]
         
     | 
| 
       101 
     | 
    
         
            -
              Read more: https://github.com/ 
     | 
| 
      
 122 
     | 
    
         
            +
              Read more: https://github.com/sidekiq/sidekiq/wiki/Using-redis-client
         
     | 
| 
       102 
123 
     | 
    
         
             
            - **Add beta support for DB transaction-aware client** [#5291]
         
     | 
| 
       103 
124 
     | 
    
         
             
              Add this line to your initializer and any jobs created during a transaction
         
     | 
| 
       104 
125 
     | 
    
         
             
              will only be pushed to Redis **after the transaction commits**. You will need to add the
         
     | 
| 
         @@ -298,7 +319,7 @@ If this is a Rails app in API mode, you need to enable sessions. 
     | 
|
| 
       298 
319 
     | 
    
         
             
            ---------
         
     | 
| 
       299 
320 
     | 
    
         | 
| 
       300 
321 
     | 
    
         
             
            - **Integrate with systemd's watchdog and notification features** [#4488]
         
     | 
| 
       301 
     | 
    
         
            -
              Set `Type=notify` in [sidekiq.service](https://github.com/ 
     | 
| 
      
 322 
     | 
    
         
            +
              Set `Type=notify` in [sidekiq.service](https://github.com/sidekiq/sidekiq/blob/4b8a8bd3ae42f6e48ae1fdaf95ed7d7af18ed8bb/examples/systemd/sidekiq.service#L30-L39). The integration works automatically.
         
     | 
| 
       302 
323 
     | 
    
         
             
            - Use `setTimeout` rather than `setInterval` to avoid thundering herd [#4480]
         
     | 
| 
       303 
324 
     | 
    
         
             
            - Fix edge case where a job can be pushed without a queue.
         
     | 
| 
       304 
325 
     | 
    
         
             
            - Flush job stats at exit [#4498]
         
     | 
| 
         @@ -311,7 +332,7 @@ If this is a Rails app in API mode, you need to enable sessions. 
     | 
|
| 
       311 
332 
     | 
    
         
             
            - Fix broken Web UI response when using NewRelic and Rack 2.1.2+. [#4440]
         
     | 
| 
       312 
333 
     | 
    
         
             
            - Update APIs to use `UNLINK`, not `DEL`. [#4449]
         
     | 
| 
       313 
334 
     | 
    
         
             
            - Fix Ruby 2.7 warnings [#4412]
         
     | 
| 
       314 
     | 
    
         
            -
            - Add support for `APP_ENV` [[95fa5d9]](https://github.com/ 
     | 
| 
      
 335 
     | 
    
         
            +
            - Add support for `APP_ENV` [[95fa5d9]](https://github.com/sidekiq/sidekiq/commit/95fa5d90192148026e52ca2902f1b83c70858ce8)
         
     | 
| 
       315 
336 
     | 
    
         | 
| 
       316 
337 
     | 
    
         
             
            6.0.4
         
     | 
| 
       317 
338 
     | 
    
         
             
            ---------
         
     | 
| 
         @@ -423,7 +444,7 @@ Sidekiq.configure_server do |config| 
     | 
|
| 
       423 
444 
     | 
    
         
             
              config.log_formatter = Sidekiq::Logger::Formatters::JSON.new
         
     | 
| 
       424 
445 
     | 
    
         
             
            end
         
     | 
| 
       425 
446 
     | 
    
         
             
            ```
         
     | 
| 
       426 
     | 
    
         
            -
            See the [Logging wiki page](https://github.com/ 
     | 
| 
      
 447 
     | 
    
         
            +
            See the [Logging wiki page](https://github.com/sidekiq/sidekiq/wiki/Logging) for more details.
         
     | 
| 
       427 
448 
     | 
    
         
             
            - **BREAKING CHANGE** Validate proper usage of the `REDIS_PROVIDER`
         
     | 
| 
       428 
449 
     | 
    
         
             
              variable.  This variable is meant to hold the name of the environment
         
     | 
| 
       429 
450 
     | 
    
         
             
              variable which contains your Redis URL, so that you can switch Redis
         
     | 
| 
         @@ -870,7 +891,7 @@ Sidekiq::Queues.clear_all 
     | 
|
| 
       870 
891 
     | 
    
         
             
            - **FIX MEMORY LEAK** Under rare conditions, threads may leak [#2598, gazay]
         
     | 
| 
       871 
892 
     | 
    
         
             
            - Add Ukrainian locale [#2561, elrakita]
         
     | 
| 
       872 
893 
     | 
    
         
             
            - Disconnect and retry Redis operations if we see a READONLY error [#2550]
         
     | 
| 
       873 
     | 
    
         
            -
            - Add server middleware testing harness; see [wiki](https://github.com/ 
     | 
| 
      
 894 
     | 
    
         
            +
            - Add server middleware testing harness; see [wiki](https://github.com/sidekiq/sidekiq/wiki/Testing#testing-server-middleware) [#2534, ryansch]
         
     | 
| 
       874 
895 
     | 
    
         | 
| 
       875 
896 
     | 
    
         
             
            3.5.0
         
     | 
| 
       876 
897 
     | 
    
         
             
            -----------
         
     | 
| 
         @@ -888,7 +909,7 @@ Sidekiq::Queues.clear_all 
     | 
|
| 
       888 
909 
     | 
    
         
             
            - Fix CSRF vulnerability in Web UI, thanks to Egor Homakov for
         
     | 
| 
       889 
910 
     | 
    
         
             
              reporting. [#2422] If you are running the Web UI as a standalone Rack app,
         
     | 
| 
       890 
911 
     | 
    
         
             
              ensure you have a [session middleware
         
     | 
| 
       891 
     | 
    
         
            -
            configured](https://github.com/ 
     | 
| 
      
 912 
     | 
    
         
            +
            configured](https://github.com/sidekiq/sidekiq/wiki/Monitoring#standalone):
         
     | 
| 
       892 
913 
     | 
    
         
             
            ```ruby
         
     | 
| 
       893 
914 
     | 
    
         
             
            use Rack::Session::Cookie, :secret => "some unique secret string here"
         
     | 
| 
       894 
915 
     | 
    
         
             
            ```
         
     | 
| 
         @@ -1272,7 +1293,7 @@ middleware, see docs/3.0-Upgrade.md.** 
     | 
|
| 
       1272 
1293 
     | 
    
         
             
              appear to be doing any work. [#1194]
         
     | 
| 
       1273 
1294 
     | 
    
         
             
            - Sidekiq's testing behavior is now dynamic.  You can choose between
         
     | 
| 
       1274 
1295 
     | 
    
         
             
              `inline` and `fake` behavior in your tests. See
         
     | 
| 
       1275 
     | 
    
         
            -
            [Testing](https://github.com/ 
     | 
| 
      
 1296 
     | 
    
         
            +
            [Testing](https://github.com/sidekiq/sidekiq/wiki/Testing) for detail. [#1193]
         
     | 
| 
       1276 
1297 
     | 
    
         
             
            - The Retries table has a new column for the error message.
         
     | 
| 
       1277 
1298 
     | 
    
         
             
            - The Web UI topbar now contains the status and live poll button.
         
     | 
| 
       1278 
1299 
     | 
    
         
             
            - 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 
     | 
    
         
             
            [](https://rubygems.org/gems/sidekiq)
         
     | 
| 
       5 
     | 
    
         
            -
            
         
     | 
| 
       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 
     | 
    
         
            -
            
         
     | 
| 
      
 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
    
    | 
         @@ -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 
     | 
    
         
            -
             
     | 
| 
      
 9 
     | 
    
         
            +
            require "ruby-prof" if ENV["PROFILE"]
         
     | 
| 
       8 
10 
     | 
    
         
             
            require "bundler/setup"
         
     | 
| 
       9 
11 
     | 
    
         
             
            Bundler.require(:default, :load_test)
         
     | 
| 
       10 
12 
     | 
    
         | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
               
     | 
| 
       14 
     | 
    
         
            -
              #  
     | 
| 
       15 
     | 
    
         
            -
               
     | 
| 
       16 
     | 
    
         
            -
               
     | 
| 
       17 
     | 
    
         
            -
               
     | 
| 
       18 
     | 
    
         
            -
               
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
       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"
         
     | 
| 
      
 54 
     | 
    
         
            +
            def Process.rss
         
     | 
| 
      
 55 
     | 
    
         
            +
              `ps -o rss= -p #{Process.pid}`.chomp.to_i
         
     | 
| 
       53 
56 
     | 
    
         
             
            end
         
     | 
| 
       54 
57 
     | 
    
         | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
            def  
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
             
     | 
| 
       66 
     | 
    
         
            -
             
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
             
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
       73 
     | 
    
         
            -
             
     | 
| 
       74 
     | 
    
         
            -
             
     | 
| 
       75 
     | 
    
         
            -
             
     | 
| 
      
 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  
     | 
| 
       82 
     | 
    
         
            -
             
     | 
| 
       83 
     | 
    
         
            -
             
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
       86 
     | 
    
         
            -
             
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
       89 
     | 
    
         
            -
             
     | 
| 
       90 
     | 
    
         
            -
             
     | 
| 
       91 
     | 
    
         
            -
             
     | 
| 
       92 
     | 
    
         
            -
             
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
       97 
     | 
    
         
            -
             
     | 
| 
       98 
     | 
    
         
            -
                 
     | 
| 
       99 
     | 
    
         
            -
             
     | 
| 
       100 
     | 
    
         
            -
             
     | 
| 
      
 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 
     | 
    
         
            -
                 
     | 
| 
       103 
     | 
    
         
            -
                 
     | 
| 
       104 
     | 
    
         
            -
             
     | 
| 
       105 
     | 
    
         
            -
             
     | 
| 
       106 
     | 
    
         
            -
                   
     | 
| 
       107 
     | 
    
         
            -
             
     | 
| 
       108 
     | 
    
         
            -
             
     | 
| 
       109 
     | 
    
         
            -
                   
     | 
| 
       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  
     | 
| 
       119 
     | 
    
         
            -
             
     | 
| 
       120 
     | 
    
         
            -
             
     | 
| 
       121 
     | 
    
         
            -
             
     | 
| 
       122 
     | 
    
         
            -
             
     | 
| 
       123 
     | 
    
         
            -
             
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
       128 
     | 
    
         
            -
             
     | 
| 
       129 
     | 
    
         
            -
              # RubyProf.start
         
     | 
| 
      
 219 
     | 
    
         
            +
            ll = Loader.new
         
     | 
| 
      
 220 
     | 
    
         
            +
            ll.configure
         
     | 
| 
       130 
221 
     | 
    
         | 
| 
       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
         
     | 
| 
      
 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
    
    
    
        data/lib/sidekiq/api.rb
    CHANGED
    
    | 
         @@ -702,7 +702,7 @@ module Sidekiq 
     | 
|
| 
       702 
702 
     | 
    
         
             
                def find_job(jid)
         
     | 
| 
       703 
703 
     | 
    
         
             
                  Sidekiq.redis do |conn|
         
     | 
| 
       704 
704 
     | 
    
         
             
                    conn.zscan(name, match: "*#{jid}*", count: 100) do |entry, score|
         
     | 
| 
       705 
     | 
    
         
            -
                      job =  
     | 
| 
      
 705 
     | 
    
         
            +
                      job = Sidekiq.load_json(entry)
         
     | 
| 
       706 
706 
     | 
    
         
             
                      matched = job["jid"] == jid
         
     | 
| 
       707 
707 
     | 
    
         
             
                      return SortedEntry.new(self, score, entry) if matched
         
     | 
| 
       708 
708 
     | 
    
         
             
                    end
         
     | 
| 
         @@ -828,6 +828,24 @@ module Sidekiq 
     | 
|
| 
       828 
828 
     | 
    
         
             
              class ProcessSet
         
     | 
| 
       829 
829 
     | 
    
         
             
                include Enumerable
         
     | 
| 
       830 
830 
     | 
    
         | 
| 
      
 831 
     | 
    
         
            +
                def self.[](identity)
         
     | 
| 
      
 832 
     | 
    
         
            +
                  exists, (info, busy, beat, quiet, rss, rtt_us) = Sidekiq.redis { |conn|
         
     | 
| 
      
 833 
     | 
    
         
            +
                    conn.multi { |transaction|
         
     | 
| 
      
 834 
     | 
    
         
            +
                      transaction.sismember("processes", identity)
         
     | 
| 
      
 835 
     | 
    
         
            +
                      transaction.hmget(identity, "info", "busy", "beat", "quiet", "rss", "rtt_us")
         
     | 
| 
      
 836 
     | 
    
         
            +
                    }
         
     | 
| 
      
 837 
     | 
    
         
            +
                  }
         
     | 
| 
      
 838 
     | 
    
         
            +
             
     | 
| 
      
 839 
     | 
    
         
            +
                  return nil if exists == 0 || info.nil?
         
     | 
| 
      
 840 
     | 
    
         
            +
             
     | 
| 
      
 841 
     | 
    
         
            +
                  hash = Sidekiq.load_json(info)
         
     | 
| 
      
 842 
     | 
    
         
            +
                  Process.new(hash.merge("busy" => busy.to_i,
         
     | 
| 
      
 843 
     | 
    
         
            +
                    "beat" => beat.to_f,
         
     | 
| 
      
 844 
     | 
    
         
            +
                    "quiet" => quiet,
         
     | 
| 
      
 845 
     | 
    
         
            +
                    "rss" => rss.to_i,
         
     | 
| 
      
 846 
     | 
    
         
            +
                    "rtt_us" => rtt_us.to_i))
         
     | 
| 
      
 847 
     | 
    
         
            +
                end
         
     | 
| 
      
 848 
     | 
    
         
            +
             
     | 
| 
       831 
849 
     | 
    
         
             
                # :nodoc:
         
     | 
| 
       832 
850 
     | 
    
         
             
                # @api private
         
     | 
| 
       833 
851 
     | 
    
         
             
                def initialize(clean_plz = true)
         
     | 
| 
         @@ -876,7 +894,7 @@ module Sidekiq 
     | 
|
| 
       876 
894 
     | 
    
         
             
                    end
         
     | 
| 
       877 
895 
     | 
    
         
             
                  }
         
     | 
| 
       878 
896 
     | 
    
         | 
| 
       879 
     | 
    
         
            -
                  result.each do |info, busy,  
     | 
| 
      
 897 
     | 
    
         
            +
                  result.each do |info, busy, beat, quiet, rss, rtt_us|
         
     | 
| 
       880 
898 
     | 
    
         
             
                    # If a process is stopped between when we query Redis for `procs` and
         
     | 
| 
       881 
899 
     | 
    
         
             
                    # when we query for `result`, we will have an item in `result` that is
         
     | 
| 
       882 
900 
     | 
    
         
             
                    # composed of `nil` values.
         
     | 
| 
         @@ -884,10 +902,10 @@ module Sidekiq 
     | 
|
| 
       884 
902 
     | 
    
         | 
| 
       885 
903 
     | 
    
         
             
                    hash = Sidekiq.load_json(info)
         
     | 
| 
       886 
904 
     | 
    
         
             
                    yield Process.new(hash.merge("busy" => busy.to_i,
         
     | 
| 
       887 
     | 
    
         
            -
                      "beat" =>  
     | 
| 
      
 905 
     | 
    
         
            +
                      "beat" => beat.to_f,
         
     | 
| 
       888 
906 
     | 
    
         
             
                      "quiet" => quiet,
         
     | 
| 
       889 
907 
     | 
    
         
             
                      "rss" => rss.to_i,
         
     | 
| 
       890 
     | 
    
         
            -
                      "rtt_us" =>  
     | 
| 
      
 908 
     | 
    
         
            +
                      "rtt_us" => rtt_us.to_i))
         
     | 
| 
       891 
909 
     | 
    
         
             
                  end
         
     | 
| 
       892 
910 
     | 
    
         
             
                end
         
     | 
| 
       893 
911 
     | 
    
         | 
| 
         @@ -943,6 +961,7 @@ module Sidekiq 
     | 
|
| 
       943 
961 
     | 
    
         
             
              #   'busy' => 10,
         
     | 
| 
       944 
962 
     | 
    
         
             
              #   'beat' => <last heartbeat>,
         
     | 
| 
       945 
963 
     | 
    
         
             
              #   'identity' => <unique string identifying the process>,
         
     | 
| 
      
 964 
     | 
    
         
            +
              #   'embedded' => true,
         
     | 
| 
       946 
965 
     | 
    
         
             
              # }
         
     | 
| 
       947 
966 
     | 
    
         
             
              class Process
         
     | 
| 
       948 
967 
     | 
    
         
             
                # :nodoc:
         
     | 
| 
         @@ -979,11 +998,17 @@ module Sidekiq 
     | 
|
| 
       979 
998 
     | 
    
         
             
                  self["version"]
         
     | 
| 
       980 
999 
     | 
    
         
             
                end
         
     | 
| 
       981 
1000 
     | 
    
         | 
| 
      
 1001 
     | 
    
         
            +
                def embedded?
         
     | 
| 
      
 1002 
     | 
    
         
            +
                  self["embedded"]
         
     | 
| 
      
 1003 
     | 
    
         
            +
                end
         
     | 
| 
      
 1004 
     | 
    
         
            +
             
     | 
| 
       982 
1005 
     | 
    
         
             
                # Signal this process to stop processing new jobs.
         
     | 
| 
       983 
1006 
     | 
    
         
             
                # It will continue to execute jobs it has already fetched.
         
     | 
| 
       984 
1007 
     | 
    
         
             
                # This method is *asynchronous* and it can take 5-10
         
     | 
| 
       985 
1008 
     | 
    
         
             
                # seconds for the process to quiet.
         
     | 
| 
       986 
1009 
     | 
    
         
             
                def quiet!
         
     | 
| 
      
 1010 
     | 
    
         
            +
                  raise "Can't quiet an embedded process" if embedded?
         
     | 
| 
      
 1011 
     | 
    
         
            +
             
     | 
| 
       987 
1012 
     | 
    
         
             
                  signal("TSTP")
         
     | 
| 
       988 
1013 
     | 
    
         
             
                end
         
     | 
| 
       989 
1014 
     | 
    
         | 
| 
         @@ -992,6 +1017,8 @@ module Sidekiq 
     | 
|
| 
       992 
1017 
     | 
    
         
             
                # This method is *asynchronous* and it can take 5-10
         
     | 
| 
       993 
1018 
     | 
    
         
             
                # seconds for the process to start shutting down.
         
     | 
| 
       994 
1019 
     | 
    
         
             
                def stop!
         
     | 
| 
      
 1020 
     | 
    
         
            +
                  raise "Can't stop an embedded process" if embedded?
         
     | 
| 
      
 1021 
     | 
    
         
            +
             
     | 
| 
       995 
1022 
     | 
    
         
             
                  signal("TERM")
         
     | 
| 
       996 
1023 
     | 
    
         
             
                end
         
     | 
| 
       997 
1024 
     | 
    
         |