sidekiq-limit_fetch 1.7 → 2.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 +4 -0
- data/benchmarks/compare.rb +49 -0
- data/lib/sidekiq-limit_fetch.rb +1 -0
- data/lib/sidekiq/limit_fetch.rb +5 -3
- data/lib/sidekiq/limit_fetch/redis.rb +13 -0
- data/sidekiq-limit_fetch.gemspec +1 -1
- data/spec/sidekiq/limit_fetch_spec.rb +4 -4
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 674ddce501d3c50f771a21a1e7546513af0a2669
|
4
|
+
data.tar.gz: f6bd2050d3e7eea9b599fc1989680b77c3e7de85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6e72377703afe1307173b6174c41bae6e4d819222431c061b2d16339a678e45968c3b51101f4a96e11253f8df17910b76a343870f1a306e322dafe7aab84e89
|
7
|
+
data.tar.gz: fc59c7b2b8c779556914a2d4aeea8282354df0a2e19154f99513a02ff8d013642b4e68fce46959d2b311a0a30d5c41bbc999d7a5a55cb7a949a8255cb9a1d716
|
data/README.md
CHANGED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'benchmark'
|
2
|
+
require 'sidekiq/cli'
|
3
|
+
|
4
|
+
total = (ARGV.shift || 50).to_i
|
5
|
+
concurrency = ARGV.shift || 1
|
6
|
+
limit = ARGV.shift
|
7
|
+
|
8
|
+
if limit
|
9
|
+
limit = nil if limit == 'nil'
|
10
|
+
|
11
|
+
$:.unshift File.expand_path './lib'
|
12
|
+
require 'sidekiq-limit_fetch'
|
13
|
+
Sidekiq::Queue['inline'].limit = limit
|
14
|
+
Sidekiq.redis {|it| it.del 'limit_fetch:probed:inline' }
|
15
|
+
end
|
16
|
+
|
17
|
+
Sidekiq::Queue.new('inline').clear
|
18
|
+
|
19
|
+
class FastJob
|
20
|
+
include Sidekiq::Worker
|
21
|
+
sidekiq_options queue: :inline
|
22
|
+
|
23
|
+
def perform(i)
|
24
|
+
puts "job N#{i} is finished"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class FinishJob
|
29
|
+
include Sidekiq::Worker
|
30
|
+
sidekiq_options queue: :inline
|
31
|
+
|
32
|
+
def perform
|
33
|
+
Process.kill 'INT', 0
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
total.times {|i| FastJob.perform_async i+1 }
|
38
|
+
FinishJob.perform_async
|
39
|
+
|
40
|
+
Sidekiq::CLI.instance.tap do |cli|
|
41
|
+
%w(validate! boot_system).each {|stub| cli.define_singleton_method(stub) {}}
|
42
|
+
cli.parse ['-q inline', '-q other', "-c #{concurrency}"]
|
43
|
+
puts Benchmark.measure {
|
44
|
+
begin
|
45
|
+
cli.run
|
46
|
+
rescue Exception
|
47
|
+
end
|
48
|
+
}
|
49
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require_relative 'sidekiq/limit_fetch'
|
data/lib/sidekiq/limit_fetch.rb
CHANGED
@@ -4,6 +4,7 @@ require 'forwardable'
|
|
4
4
|
class Sidekiq::LimitFetch
|
5
5
|
autoload :UnitOfWork, 'sidekiq/limit_fetch/unit_of_work'
|
6
6
|
|
7
|
+
require_relative 'limit_fetch/redis'
|
7
8
|
require_relative 'limit_fetch/singleton'
|
8
9
|
require_relative 'limit_fetch/queues'
|
9
10
|
require_relative 'limit_fetch/global/semaphore'
|
@@ -11,6 +12,7 @@ class Sidekiq::LimitFetch
|
|
11
12
|
require_relative 'limit_fetch/global/monitor'
|
12
13
|
require_relative 'extensions/queue'
|
13
14
|
|
15
|
+
include Redis
|
14
16
|
Sidekiq.options[:fetch] = self
|
15
17
|
|
16
18
|
def self.bulk_requeue(jobs)
|
@@ -30,13 +32,13 @@ class Sidekiq::LimitFetch
|
|
30
32
|
private
|
31
33
|
|
32
34
|
def fetch_message
|
33
|
-
queue, _ =
|
35
|
+
queue, _ = redis_brpop *@queues.acquire, Sidekiq::Fetcher::TIMEOUT
|
34
36
|
ensure
|
35
37
|
@queues.release_except queue
|
36
38
|
end
|
37
39
|
|
38
|
-
def
|
40
|
+
def redis_brpop(*args)
|
39
41
|
return if args.size < 2
|
40
|
-
|
42
|
+
redis {|it| it.brpop *args }
|
41
43
|
end
|
42
44
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Sidekiq::LimitFetch::Redis
|
2
|
+
# prevent blocking of fetcher
|
3
|
+
# more bullet-proof and faster (O_O)
|
4
|
+
# than using Celluloid::IO
|
5
|
+
def redis
|
6
|
+
Sidekiq.redis do |redis|
|
7
|
+
begin
|
8
|
+
Celluloid::Future.new { yield redis }.value
|
9
|
+
end
|
10
|
+
end
|
11
|
+
rescue Celluloid::Task::TerminatedError
|
12
|
+
end
|
13
|
+
end
|
data/sidekiq-limit_fetch.gemspec
CHANGED
@@ -4,8 +4,8 @@ describe Sidekiq::LimitFetch do
|
|
4
4
|
before :each do
|
5
5
|
Sidekiq.redis do |it|
|
6
6
|
it.del 'queue:queue1'
|
7
|
-
it.
|
8
|
-
it.
|
7
|
+
it.lpush 'queue:queue1', 'task1'
|
8
|
+
it.lpush 'queue:queue1', 'task2'
|
9
9
|
it.expire 'queue:queue1', 30
|
10
10
|
end
|
11
11
|
end
|
@@ -30,7 +30,7 @@ describe Sidekiq::LimitFetch do
|
|
30
30
|
Sidekiq::Queue['queue2'].busy.should == 0
|
31
31
|
|
32
32
|
work = subject.retrieve_work
|
33
|
-
work.message.should == '
|
33
|
+
work.message.should == 'task1'
|
34
34
|
|
35
35
|
Sidekiq::Queue['queue1'].busy.should == 1
|
36
36
|
Sidekiq::Queue['queue2'].busy.should == 0
|
@@ -42,6 +42,6 @@ describe Sidekiq::LimitFetch do
|
|
42
42
|
Sidekiq::Queue['queue2'].busy.should == 0
|
43
43
|
|
44
44
|
work = subject.retrieve_work
|
45
|
-
work.message.should == '
|
45
|
+
work.message.should == 'task2'
|
46
46
|
end
|
47
47
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq-limit_fetch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '
|
4
|
+
version: '2.0'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- brainopia
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sidekiq
|
@@ -72,12 +72,15 @@ files:
|
|
72
72
|
- LICENSE.txt
|
73
73
|
- README.md
|
74
74
|
- Rakefile
|
75
|
+
- benchmarks/compare.rb
|
76
|
+
- lib/sidekiq-limit_fetch.rb
|
75
77
|
- lib/sidekiq/extensions/queue.rb
|
76
78
|
- lib/sidekiq/limit_fetch.rb
|
77
79
|
- lib/sidekiq/limit_fetch/global/monitor.rb
|
78
80
|
- lib/sidekiq/limit_fetch/global/selector.rb
|
79
81
|
- lib/sidekiq/limit_fetch/global/semaphore.rb
|
80
82
|
- lib/sidekiq/limit_fetch/queues.rb
|
83
|
+
- lib/sidekiq/limit_fetch/redis.rb
|
81
84
|
- lib/sidekiq/limit_fetch/singleton.rb
|
82
85
|
- lib/sidekiq/limit_fetch/unit_of_work.rb
|
83
86
|
- sidekiq-limit_fetch.gemspec
|
@@ -106,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
109
|
version: '0'
|
107
110
|
requirements: []
|
108
111
|
rubyforge_project:
|
109
|
-
rubygems_version: 2.0.
|
112
|
+
rubygems_version: 2.0.2
|
110
113
|
signing_key:
|
111
114
|
specification_version: 4
|
112
115
|
summary: Sidekiq strategy to support queue limits
|
@@ -117,4 +120,3 @@ test_files:
|
|
117
120
|
- spec/sidekiq/limit_fetch/semaphore_spec.rb
|
118
121
|
- spec/sidekiq/limit_fetch_spec.rb
|
119
122
|
- spec/spec_helper.rb
|
120
|
-
has_rdoc:
|