sidekiq-cluster 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +32 -13
- data/lib/sidekiq/cluster/cli.rb +14 -13
- data/lib/sidekiq/cluster/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9bd053636c77d2a9013f9eb4eaa7e0ebd387ca4e
|
4
|
+
data.tar.gz: 2a70abcf93df422f9dd27c2ddc9b06ca9182d5b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1652ee6f5eb02205b29db3387d5d8b5b040018827416e87f5c219fe0a82837743a69840d4e162f12e1fc158d7c3888cab4342a34da7a76e5525937d28699f66b
|
7
|
+
data.tar.gz: b9bb74bca5603651e1e461a2853a3fc7e23e2d1e02aadf73a1a79aa110a48c182088de889430d74cf2dfb65ba48c85f36ba27983d5be3a2fc1ea2d9db7704713
|
data/README.md
CHANGED
@@ -2,18 +2,37 @@
|
|
2
2
|
|
3
3
|
## Sidekiq Cluster
|
4
4
|
|
5
|
-
This is a tiny gem that allows starting sidekiq using multiple processes.
|
5
|
+
This is a tiny gem that allows starting sidekiq using multiple processes. It is originally based on the wonderful [Honebadger Cluster Script](http://blog.honeybadger.io/introducing-our-sidekiq-cluster-script/).
|
6
6
|
|
7
|
-
|
7
|
+
Features:
|
8
|
+
|
9
|
+
* It does not depend on any particular version of sidekiq, as long as the CLI class of Sidekiq remains named the same.
|
10
|
+
|
11
|
+
* It does not attempt to replicate Sidekiq's command line options. Script itself can be controlled with its own CLI options preceeding the double dash `--`. Options to Sidekiq are expected after the double dash.
|
12
|
+
|
13
|
+
* You can specify **max number of processes** and **max total RAM used by this cluster** (expressed as a percentage of total). If one of the Sidekiq processes exceeeds it, it is automatically restarted.
|
8
14
|
|
9
15
|
### Usage
|
10
16
|
|
11
|
-
|
17
|
+
The easiest way to use Sidekiq Cluster is to add it to your Gemfile:
|
12
18
|
|
19
|
+
```ruby
|
20
|
+
gem 'sidekiq-cluster', require: false
|
13
21
|
```
|
14
|
-
|
22
|
+
|
23
|
+
Run `bundle`, and then start Sidekiq cluster like so (this starts exactly two Sidekiq Processes):
|
24
|
+
|
25
|
+
```bash
|
26
|
+
# this starts sidekiq with default options
|
27
|
+
$ bundle exec sidekiq-cluster -N 2
|
28
|
+
|
29
|
+
# this starts sidekiq with custom options
|
30
|
+
$ bundle exec sidekiq-cluster -N 2 -- -r $(pwd) -q default,10 -q high,100
|
15
31
|
```
|
16
32
|
|
33
|
+
### Command Line Options
|
34
|
+
|
35
|
+
|
17
36
|
Then try running it with `--help`:
|
18
37
|
|
19
38
|
```
|
@@ -24,7 +43,7 @@ USAGE
|
|
24
43
|
|
25
44
|
EXAMPLES
|
26
45
|
$ cd rails_app
|
27
|
-
$ bundle exec sidekiq-cluster -N 2 -- -c 10 -q default,12 -
|
46
|
+
$ bundle exec sidekiq-cluster -N 2 -- -c 10 -q default,12 -L log/sidekiq.log
|
28
47
|
|
29
48
|
SIDEKIQ CLUSTER OPTIONS
|
30
49
|
-n, --name=NAME the name of this cluster, used when
|
@@ -33,7 +52,7 @@ SIDEKIQ CLUSTER OPTIONS
|
|
33
52
|
-P, --pidfile=FILE Pidfile prefix,
|
34
53
|
eg "/var/www/shared/config/sidekiq.pid"
|
35
54
|
|
36
|
-
-
|
55
|
+
-L, --logfile=FILE Logfile for the cluster script
|
37
56
|
|
38
57
|
-M, --max-memory=PERCENT Maximum percent RAM that this
|
39
58
|
cluster should not exceed. Defaults to 80%.
|
@@ -54,13 +73,13 @@ SIDEKIQ CLUSTER OPTIONS
|
|
54
73
|
$ cd rails-app
|
55
74
|
$ echo "gem 'sidekiq-cluster'" >> Gemfile
|
56
75
|
$ bundle install
|
57
|
-
$ bundle exec sidekiq-cluster \
|
58
|
-
|
59
|
-
|
60
|
-
-
|
61
|
-
|
62
|
-
-
|
63
|
-
-- \
|
76
|
+
$ bundle exec sidekiq-cluster \ # these arguments are for sidekiq-cluster:
|
77
|
+
--pidfile /var/pids/sidekiq.pid \
|
78
|
+
--name default \
|
79
|
+
--max-memory 90 \
|
80
|
+
--logfile /var/log/sidekiq-cluster.log \
|
81
|
+
--num-processes 2 \
|
82
|
+
-- \ # these arguments are for sidekiq:
|
64
83
|
-L /var/log/sidekiq.log -c 10 -e production -q default,10 -q critical,20
|
65
84
|
```
|
66
85
|
|
data/lib/sidekiq/cluster/cli.rb
CHANGED
@@ -24,8 +24,15 @@ module Sidekiq
|
|
24
24
|
:logger
|
25
25
|
|
26
26
|
def initialize(argv = ARGV.dup)
|
27
|
-
self.argv
|
28
|
-
self.
|
27
|
+
self.argv = argv
|
28
|
+
self.name = 'default'
|
29
|
+
self.pid_prefix = '/tmp/sidekiq.pid'
|
30
|
+
self.sidekiq_argv = []
|
31
|
+
self.log_device = STDOUT
|
32
|
+
self.memory_percentage_limit = MAX_RAM_PCT
|
33
|
+
self.process_count = Etc.nprocessors - 1
|
34
|
+
self.processes = {}
|
35
|
+
self.pids = []
|
29
36
|
end
|
30
37
|
|
31
38
|
def per_process_memory_limit
|
@@ -39,7 +46,6 @@ module Sidekiq
|
|
39
46
|
end
|
40
47
|
|
41
48
|
def start_main_loop!
|
42
|
-
self.processes = {}
|
43
49
|
start_children.each do |descriptor|
|
44
50
|
processes[descriptor.pid] = descriptor
|
45
51
|
end
|
@@ -47,7 +53,7 @@ module Sidekiq
|
|
47
53
|
self.pids = processes.keys
|
48
54
|
self.watch_children = true
|
49
55
|
|
50
|
-
|
56
|
+
main
|
51
57
|
setup_signal_traps
|
52
58
|
|
53
59
|
Process.waitall
|
@@ -68,11 +74,6 @@ module Sidekiq
|
|
68
74
|
else
|
69
75
|
split_argv! if argv.include?('--')
|
70
76
|
end
|
71
|
-
|
72
|
-
self.log_device = STDOUT
|
73
|
-
self.memory_percentage_limit = MAX_RAM_PCT
|
74
|
-
self.process_count = Etc.nprocessors - 1
|
75
|
-
|
76
77
|
init_logger!
|
77
78
|
parse_args!
|
78
79
|
end
|
@@ -102,7 +103,7 @@ module Sidekiq
|
|
102
103
|
end
|
103
104
|
end
|
104
105
|
|
105
|
-
def
|
106
|
+
def main
|
106
107
|
Thread.new do
|
107
108
|
info 'watching for outsized Sidekiq processes...'
|
108
109
|
loop do
|
@@ -138,7 +139,7 @@ module Sidekiq
|
|
138
139
|
|
139
140
|
Process.fork do
|
140
141
|
process_argv = sidekiq_argv.dup << '-P' << pid_file(index)
|
141
|
-
process_argv << '--tag' << "sidekiq.#{name}"
|
142
|
+
process_argv << '--tag' << "sidekiq.#{name}.#{index + 1}"
|
142
143
|
info "starting up sidekiq instance #{index} with ARGV: 'bundle exec sidekiq #{process_argv.join(' ')}'"
|
143
144
|
begin
|
144
145
|
cli = Sidekiq::CLI.instance
|
@@ -154,7 +155,7 @@ module Sidekiq
|
|
154
155
|
end
|
155
156
|
|
156
157
|
def pid_file(index)
|
157
|
-
"#{pid_prefix}.#{index}"
|
158
|
+
"#{pid_prefix}.#{index + 1}"
|
158
159
|
end
|
159
160
|
|
160
161
|
def start_children
|
@@ -239,7 +240,7 @@ module Sidekiq
|
|
239
240
|
'eg "/var/www/shared/config/sidekiq.pid"', ' ') do |v|
|
240
241
|
self.pid_prefix = v
|
241
242
|
end
|
242
|
-
opts.on('-
|
243
|
+
opts.on('-L', '--logfile=FILE',
|
243
244
|
'Logfile for the cluster script', ' ') do |v|
|
244
245
|
self.log_device = v
|
245
246
|
init_logger!
|