haystack_worker 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +42 -0
- data/bin/haystack +6 -0
- data/ext/haystack_worker/extconf.rb +3 -0
- data/ext/haystack_worker/haystack_worker.c +72 -0
- data/ext/haystack_worker/lookup.h +1794 -0
- data/ext/haystack_worker/macros.h +11 -0
- data/lib/haystack_worker/base.rb +19 -0
- data/lib/haystack_worker/benchmark.rb +28 -0
- data/lib/haystack_worker/haystack_worker.bundle +0 -0
- data/lib/haystack_worker/jobs.rb +35 -0
- data/lib/haystack_worker/surpluses.rb +15 -0
- data/lib/haystack_worker.rb +10 -0
- metadata +122 -0
@@ -0,0 +1,11 @@
|
|
1
|
+
#define F(index) \
|
2
|
+
for (attempt[index] = ranges[index][0]; \
|
3
|
+
attempt[index] <= ranges[index][1]; \
|
4
|
+
attempt[index]++)
|
5
|
+
|
6
|
+
#define YIELD_ATTEMPTS \
|
7
|
+
int attempt[26]; \
|
8
|
+
F(0) F(1) F(2) F(3) F(4) F(5) F(6) \
|
9
|
+
F(7) F(8) F(9) F(10) F(11) F(12) F(13) \
|
10
|
+
F(14) F(15) F(16) F(17) F(18) F(19) F(20) \
|
11
|
+
F(21) F(22) F(23) F(24) F(25)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class HaystackWorker
|
2
|
+
include Jobs, Surpluses, Benchmark
|
3
|
+
|
4
|
+
def initialize(haystack_domain)
|
5
|
+
@haystack_domain = haystack_domain
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.work(haystack_domain)
|
9
|
+
new(haystack_domain).work
|
10
|
+
end
|
11
|
+
|
12
|
+
def work
|
13
|
+
id, ranges = request_job
|
14
|
+
loop do
|
15
|
+
results = surpluses(ranges)
|
16
|
+
id, ranges = respond_with(id, results)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'benchmark'
|
2
|
+
|
3
|
+
module HaystackWorker::Benchmark
|
4
|
+
def benchmark(exponentials = 5..7)
|
5
|
+
puts "\n::::: Benchmarking :::::\n\n"
|
6
|
+
|
7
|
+
exponentials.map do |i|
|
8
|
+
number_of_attempts = 10 ** i
|
9
|
+
attempts = [1..10] * i + [1..1] * (26 - i)
|
10
|
+
|
11
|
+
puts "Job size: #{number_of_attempts}\n\n"
|
12
|
+
|
13
|
+
times = 5.times.map do
|
14
|
+
time = Benchmark.realtime do
|
15
|
+
surpluses(attempts)
|
16
|
+
end
|
17
|
+
puts time
|
18
|
+
time
|
19
|
+
end
|
20
|
+
|
21
|
+
average = times.inject(:+) / times.size
|
22
|
+
puts "\nAverage: #{average}"
|
23
|
+
|
24
|
+
rate = (number_of_attempts / average).round
|
25
|
+
puts "Rate: #{rate} attempts/s/thread\n\n"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
Binary file
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module HaystackWorker::Jobs
|
2
|
+
def request_job
|
3
|
+
respond_with(nil, nil)
|
4
|
+
end
|
5
|
+
|
6
|
+
def respond_with(id, results)
|
7
|
+
path = job_path(id)
|
8
|
+
data = data_for(results)
|
9
|
+
|
10
|
+
json = Net::HTTP.post_form(path, data).body
|
11
|
+
hash = with_support_for_ranges { JSON.parse(json) }
|
12
|
+
|
13
|
+
[hash['id'], hash['ranges']]
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
def data_for(results)
|
18
|
+
{ :results => results.to_json }
|
19
|
+
end
|
20
|
+
|
21
|
+
def job_path(id = nil)
|
22
|
+
URI("http://#@haystack_domain/job/#{id}")
|
23
|
+
end
|
24
|
+
|
25
|
+
def with_support_for_ranges(&block)
|
26
|
+
hash = yield
|
27
|
+
|
28
|
+
if hash['ranges']
|
29
|
+
ranges = hash['ranges'].map { |r| eval(r) }
|
30
|
+
hash.merge!('ranges' => ranges)
|
31
|
+
end
|
32
|
+
|
33
|
+
hash
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module HaystackWorker::Surpluses
|
2
|
+
def surpluses(*ranges)
|
3
|
+
validate(ranges)
|
4
|
+
_surpluses(ranges.map { |r| [r.min, r.max] })
|
5
|
+
end
|
6
|
+
|
7
|
+
private
|
8
|
+
def validate(ranges)
|
9
|
+
ranges.flatten!
|
10
|
+
|
11
|
+
message = 'Please specify 26 ranges as an argument.'
|
12
|
+
raise ArgumentError.new(message) unless ranges.count == 26
|
13
|
+
raise TypeError.new(message) unless ranges.all? { |r| r.is_a?(Range) }
|
14
|
+
end
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: haystack_worker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Christopher Patuzzo
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: json
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: fakeweb
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rack
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: Description
|
79
|
+
email: chris.patuzzo@gmail.com
|
80
|
+
executables:
|
81
|
+
- haystack
|
82
|
+
extensions:
|
83
|
+
- ext/haystack_worker/extconf.rb
|
84
|
+
extra_rdoc_files: []
|
85
|
+
files:
|
86
|
+
- README.md
|
87
|
+
- lib/haystack_worker/base.rb
|
88
|
+
- lib/haystack_worker/benchmark.rb
|
89
|
+
- lib/haystack_worker/haystack_worker.bundle
|
90
|
+
- lib/haystack_worker/jobs.rb
|
91
|
+
- lib/haystack_worker/surpluses.rb
|
92
|
+
- lib/haystack_worker.rb
|
93
|
+
- ext/haystack_worker/haystack_worker.c
|
94
|
+
- ext/haystack_worker/lookup.h
|
95
|
+
- ext/haystack_worker/macros.h
|
96
|
+
- ext/haystack_worker/extconf.rb
|
97
|
+
- bin/haystack
|
98
|
+
homepage: https://github.com/cpatuzzo/haystack_worker
|
99
|
+
licenses: []
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ! '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
requirements: []
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 1.8.23
|
119
|
+
signing_key:
|
120
|
+
specification_version: 3
|
121
|
+
summary: Summary
|
122
|
+
test_files: []
|