zold 0.14.25 → 0.14.26
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 +4 -4
- data/lib/zold/node/farm.rb +2 -2
- data/lib/zold/remotes.rb +5 -16
- data/lib/zold/version.rb +1 -1
- data/test/test_remotes.rb +32 -0
- 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: f4395e269936df99f2f80289e47287be347e2f3a
|
4
|
+
data.tar.gz: 5719f9f81b7c4c70860c67a1903cfc01b5dbe95c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8849738bb1417903741cb729467ae2f96e1a244578a8702a0e4b0d69f674ba710587c17bed2ff023b639aed6d0825748f4e970f371dd7360a3d3692ab6a9898
|
7
|
+
data.tar.gz: 4d84feac840f4e4992025e8938ce24a62ec3d56d14b5393460984e8d8de907d8295f1b07b6f485b19f2e03342ff113d9dbeb4ceed5c0159229a4c0357dfe5f42
|
data/lib/zold/node/farm.rb
CHANGED
@@ -147,8 +147,8 @@ module Zold
|
|
147
147
|
return unless s.port == port
|
148
148
|
return unless s.strength >= strength
|
149
149
|
Thread.current.name = s.to_mnemo
|
150
|
-
|
151
|
-
Open3.popen2e(
|
150
|
+
bin = File.expand_path(File.join(File.dirname(__FILE__), '../../../bin/zold'))
|
151
|
+
Open3.popen2e("ruby #{bin} next \"#{s}\"") do |stdin, stdout, thr|
|
152
152
|
@log.debug("Score counting started in process ##{thr.pid}")
|
153
153
|
begin
|
154
154
|
stdin.close
|
data/lib/zold/remotes.rb
CHANGED
@@ -168,13 +168,14 @@ module Zold
|
|
168
168
|
def iterate(log, farm: Farm::Empty.new)
|
169
169
|
raise 'Log can\'t be nil' if log.nil?
|
170
170
|
raise 'Farm can\'t be nil' if farm.nil?
|
171
|
-
|
171
|
+
list = all
|
172
|
+
return if list.empty?
|
172
173
|
best = farm.best[0]
|
173
174
|
require_relative 'score'
|
174
175
|
score = best.nil? ? Score::ZERO : best
|
175
176
|
idx = 0
|
176
|
-
pool = Concurrent::FixedThreadPool.new([
|
177
|
-
|
177
|
+
pool = Concurrent::FixedThreadPool.new([list.count, Concurrent.processor_count * 4].min, max_queue: 0)
|
178
|
+
list.each do |r|
|
178
179
|
pool.post do
|
179
180
|
Thread.current.abort_on_exception = true
|
180
181
|
Thread.current.name = 'remotes'
|
@@ -192,9 +193,8 @@ module Zold
|
|
192
193
|
raise 'Took too long to execute' if (Time.now - start).round > @timeout
|
193
194
|
rescue StandardError => e
|
194
195
|
error(r[:host], r[:port])
|
195
|
-
errors = errors(r[:host], r[:port])
|
196
196
|
log.info("#{Rainbow("#{r[:host]}:#{r[:port]}").red}: #{e.message} \
|
197
|
-
in #{(Time.now - start).round}s
|
197
|
+
in #{(Time.now - start).round}s")
|
198
198
|
log.debug(Backtrace.new(e).to_s)
|
199
199
|
remove(r[:host], r[:port]) if errors > Remotes::TOLERANCE
|
200
200
|
end
|
@@ -204,17 +204,6 @@ in #{(Time.now - start).round}s; errors=#{errors}")
|
|
204
204
|
pool.kill unless pool.wait_for_termination(5 * 60)
|
205
205
|
end
|
206
206
|
|
207
|
-
def errors(host, port = Remotes::PORT)
|
208
|
-
raise 'Host can\'t be nil' if host.nil?
|
209
|
-
raise 'Port can\'t be nil' if port.nil?
|
210
|
-
raise 'Port has to be of type Integer' unless port.is_a?(Integer)
|
211
|
-
@mutex.synchronize do
|
212
|
-
list = load
|
213
|
-
raise "#{host}:#{port} is absent among #{list.count} remotes" unless exists?(host, port)
|
214
|
-
list.find { |r| r[:host] == host.downcase && r[:port] == port }[:errors]
|
215
|
-
end
|
216
|
-
end
|
217
|
-
|
218
207
|
def error(host, port = Remotes::PORT)
|
219
208
|
raise 'Host can\'t be nil' if host.nil?
|
220
209
|
raise 'Port can\'t be nil' if port.nil?
|
data/lib/zold/version.rb
CHANGED
data/test/test_remotes.rb
CHANGED
@@ -215,6 +215,38 @@ class TestRemotes < Minitest::Test
|
|
215
215
|
end
|
216
216
|
end
|
217
217
|
|
218
|
+
def test_quickly_ads_and_reads
|
219
|
+
Dir.mktmpdir do |dir|
|
220
|
+
remotes = Zold::Remotes.new(file: File.join(dir, 'uu-90.csv'))
|
221
|
+
remotes.clean
|
222
|
+
threads = 20
|
223
|
+
pool = Concurrent::FixedThreadPool.new(threads)
|
224
|
+
done = Concurrent::AtomicFixnum.new
|
225
|
+
start = Time.now
|
226
|
+
alive = true
|
227
|
+
100.times { |i| remotes.add('192.168.0.1', 8080 + i) }
|
228
|
+
threads.times do |i|
|
229
|
+
pool.post do
|
230
|
+
loop do
|
231
|
+
break unless alive
|
232
|
+
Zold::VerboseThread.new(test_log).run(true) do
|
233
|
+
remotes.add('127.0.0.1', 8080 + i)
|
234
|
+
remotes.error('127.0.0.1', 8080 + i)
|
235
|
+
remotes.all
|
236
|
+
remotes.iterate(test_log) { done.increment }
|
237
|
+
remotes.remove('127.0.0.1', 8080 + i)
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
sleep 0.1 while done.value < 1000
|
243
|
+
alive = false
|
244
|
+
pool.shutdown
|
245
|
+
pool.wait_for_termination(10)
|
246
|
+
test_log.info("Total time: #{Time.now - start}")
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
218
250
|
def test_empty_remotes
|
219
251
|
remotes = Zold::Remotes::Empty.new(file: '/tmp/empty')
|
220
252
|
assert(remotes.is_a?(Zold::Remotes))
|