sidekiq-cluster 0.0.1 → 0.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: da72edd26d09ba063231b3b73a06ce891ed34fd2
4
- data.tar.gz: 3dc9fcb9359f7626a26b62a1694c20365ccdd5ed
3
+ metadata.gz: 9bd053636c77d2a9013f9eb4eaa7e0ebd387ca4e
4
+ data.tar.gz: 2a70abcf93df422f9dd27c2ddc9b06ca9182d5b1
5
5
  SHA512:
6
- metadata.gz: 14fedbc8f6500d3c27dfc7821bf4582ef931187b6ccf24314184ff060f2bd70f187203b54ca819c7cd384d7dea3cca03d2f42bca2f502d4db89492b020978862
7
- data.tar.gz: 2222f7178526b52c8bd8e925e1c6ea72ac63c7f0d38c06a1208b33af4accad001f64fa1e7c73eb99222a9efb33999fbd591a92bb863f6ed264506690d87cfefd
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
- It does not depend on any particular version of sidekiq, as long as the CLI class of Sidekiq remains named the same.
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
- Install the gem:
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
- gem install sidekiq-cluster
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 -l log/sidekiq.log
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
- -l, --logfile=FILE Logfile for the cluster script
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
- -P /var/pids/sidekiq.pid \ # these are arguments to sidekiq-cluster
59
- -n default \
60
- -M 90 \
61
- -L /var/log/sidekiq-cluster.log \
62
- -N 2 \
63
- -- \ # these are arguments for sidekiq.
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
 
@@ -24,8 +24,15 @@ module Sidekiq
24
24
  :logger
25
25
 
26
26
  def initialize(argv = ARGV.dup)
27
- self.argv = argv
28
- self.sidekiq_argv = []
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
- initiate_main_loop
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 initiate_main_loop
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('-l', '--logfile=FILE',
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!
@@ -1,6 +1,6 @@
1
1
  module Sidekiq
2
2
  module Cluster
3
- VERSION = '0.0.1'
3
+ VERSION = '0.1.0'
4
4
  end
5
5
  end
6
6
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-cluster
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Konstantin Gredeskoul