zold 0.13.20 → 0.13.21
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/zold/node/farm.rb +39 -22
- data/lib/zold/node/front.rb +5 -0
- data/lib/zold/version.rb +1 -1
- data/test/node/test_farm.rb +3 -1
- data/test/node/test_front.rb +3 -2
- 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: 9b54e147de6f13a87996515785862a09da82b1a5
|
4
|
+
data.tar.gz: 332d33f707a6ad855001b9d77738d2f497622ef7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6696d078025e97891007c9295fd2210de314c4dbbcef5e968fc4d7a9dd5b614c81903a4066ee4016074c7974321c1e3d656825f01d934ae0dcc55869aa693041
|
7
|
+
data.tar.gz: 4463d7a107bbb6acb7a89931ae745dcc05598005cccaca4caf56c2484b5376f3ee07b595fca407376432bf4fcf7461408ff6f88aae52718165e784bf24faaff0
|
data/lib/zold/node/farm.rb
CHANGED
@@ -38,7 +38,6 @@ module Zold
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
attr_reader :best
|
42
41
|
def initialize(invoice, cache, log: Log::Quiet.new)
|
43
42
|
@log = log
|
44
43
|
@cache = cache
|
@@ -46,14 +45,28 @@ module Zold
|
|
46
45
|
@scores = []
|
47
46
|
@threads = []
|
48
47
|
@best = []
|
49
|
-
@
|
48
|
+
@mutex = Mutex.new
|
49
|
+
end
|
50
|
+
|
51
|
+
def best
|
52
|
+
@mutex.synchronize do
|
53
|
+
@best.to_a
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def to_text
|
58
|
+
@threads.map do |t|
|
59
|
+
"#{t.name}: status=#{t.status}; alive=#{t.alive};\n #{t.backtrace.join("\n ")}"
|
60
|
+
end.join("\n")
|
50
61
|
end
|
51
62
|
|
52
63
|
def to_json
|
53
64
|
{
|
54
|
-
threads: @threads.map
|
65
|
+
threads: @threads.map do |t|
|
66
|
+
"#{t.name}/#{t.status}/{t.alive? ? 'A' : 'D'}"
|
67
|
+
end.join(', '),
|
55
68
|
scores: @scores.size,
|
56
|
-
best: @best.
|
69
|
+
best: @best.map(&:value).join(', '),
|
57
70
|
history: history.count
|
58
71
|
}
|
59
72
|
end
|
@@ -67,17 +80,19 @@ module Zold
|
|
67
80
|
@log.info("#{@scores.size} scores pre-loaded, the best is: #{@best[0]}")
|
68
81
|
@threads = (1..threads).map do |t|
|
69
82
|
Thread.new do
|
70
|
-
|
71
|
-
|
72
|
-
|
83
|
+
Thread.current.name = "f#{t}"
|
84
|
+
loop do
|
85
|
+
VerboseThread.new(@log).run do
|
86
|
+
cycle(host, port, strength, threads)
|
87
|
+
end
|
73
88
|
end
|
74
89
|
end
|
75
90
|
end
|
76
91
|
@threads << Thread.new do
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
92
|
+
Thread.current.name = 'cleaner'
|
93
|
+
loop do
|
94
|
+
sleep(60) unless strength == 1 # which will only happen in tests
|
95
|
+
VerboseThread.new(@log).run do
|
81
96
|
clean(host, port, strength, threads)
|
82
97
|
end
|
83
98
|
end
|
@@ -105,13 +120,18 @@ module Zold
|
|
105
120
|
private
|
106
121
|
|
107
122
|
def clean(host, port, strength, threads)
|
108
|
-
|
109
|
-
|
110
|
-
@
|
111
|
-
@best
|
123
|
+
@mutex.synchronize do
|
124
|
+
before = @best.map(&:value).max
|
125
|
+
@best = @best.reject(&:expired?).sort_by(&:value).reverse
|
126
|
+
@best = @best.take(threads) unless threads.zero?
|
127
|
+
if @scores.length < threads || @best.count < threads
|
128
|
+
zero = Score.new(Time.now, host, port, @invoice, strength: strength)
|
129
|
+
@scores << zero
|
130
|
+
@best << zero
|
131
|
+
end
|
132
|
+
after = @best.map(&:value).max
|
133
|
+
@log.debug("#{Thread.current.name}: best score is #{@best[0]}") if before != after && !after.zero?
|
112
134
|
end
|
113
|
-
@best = @best.reject(&:expired?).sort_by(&:value).reverse
|
114
|
-
@best = @best.take(threads) unless threads.zero?
|
115
135
|
end
|
116
136
|
|
117
137
|
def cycle(host, port, strength, threads)
|
@@ -122,14 +142,11 @@ module Zold
|
|
122
142
|
return unless s.port == port
|
123
143
|
return unless s.strength >= strength
|
124
144
|
n = s.next
|
125
|
-
@
|
126
|
-
before = @best.map(&:value).max
|
145
|
+
@mutex.synchronize do
|
127
146
|
save(n)
|
128
147
|
@best << n
|
129
|
-
clean(host, port, strength, threads)
|
130
|
-
after = @best.map(&:value).max
|
131
|
-
@log.debug("#{Thread.current.name}: best score is #{@best[0]}") if before != after && !after.zero?
|
132
148
|
end
|
149
|
+
clean(host, port, strength, threads)
|
133
150
|
@scores << n
|
134
151
|
end
|
135
152
|
|
data/lib/zold/node/front.rb
CHANGED
data/lib/zold/version.rb
CHANGED
data/test/node/test_farm.rb
CHANGED
@@ -90,7 +90,9 @@ class FarmTest < Minitest::Test
|
|
90
90
|
farm.start(score.host, score.port, threads: 1, strength: score.strength) do
|
91
91
|
100.times do
|
92
92
|
sleep(0.1)
|
93
|
-
|
93
|
+
b = farm.best[0]
|
94
|
+
assert(!b.nil?)
|
95
|
+
break if b.value.zero?
|
94
96
|
end
|
95
97
|
assert_equal(0, farm.best[0].value)
|
96
98
|
end
|
data/test/node/test_front.rb
CHANGED
@@ -36,6 +36,7 @@ class FrontTest < Minitest::Test
|
|
36
36
|
'/',
|
37
37
|
'/remotes',
|
38
38
|
'/version',
|
39
|
+
'/farm',
|
39
40
|
'/score'
|
40
41
|
],
|
41
42
|
'404' => [
|
@@ -146,8 +147,8 @@ class FrontTest < Minitest::Test
|
|
146
147
|
"Expected HTTP 200 OK: Found #{response.code}"
|
147
148
|
)
|
148
149
|
assert_operator(
|
149
|
-
|
150
|
-
'Expected the content to be smaller than
|
150
|
+
600, :>, response['content-length'].to_i,
|
151
|
+
'Expected the content to be smaller than 600 bytes for gzip'
|
151
152
|
)
|
152
153
|
end
|
153
154
|
end
|