lib/zold/node/farm.rb in zold-0.13.16 vs lib/zold/node/farm.rb in zold-0.13.17

- old
+ new

@@ -67,36 +67,36 @@ @threads = (1..threads).map do |t| Thread.new do VerboseThread.new(@log).run do Thread.current.name = "farm-#{t}" loop do - if @scores.length < 4 + if @scores.length < threads @scores << Score.new( Time.now, host, port, @invoice, strength: strength ) end s = @scores.pop next unless s.valid? next unless s.host == host next unless s.port == port - next if s.expired?(20) - next if s.strength < strength + next unless s.strength >= strength + n = s.next @semaphore.synchronize do - save(s) before = @best.map(&:value).max - @best << s + save(n) + @best << n after = @best.map(&:value).max - @best.reject! { |b| b.value < after } - @log.debug("#{Thread.current.name}: best score is #{@best[0]}") if before != after + @best = @best.reject(&:expired?).sort_by(&:value).reverse.take(threads) + @log.debug("#{Thread.current.name}: best score is #{@best[0]}") if before != after && !after.zero? end - @scores << s.next + @scores << n end end end end - @log.info("Farm started with #{threads} threads at #{host}:#{port}") + @log.info("Farm started with #{threads} threads at #{host}:#{port}, strength is #{strength}") end def stop @log.info("Terminating the farm with #{@threads.count} threads...") start = Time.now @@ -117,10 +117,9 @@ def history(max = 16) if File.exist?(@cache) AtomicFile.new(@cache).read .split(/\n/) .map { |t| Score.parse(t) } - .reject(&:expired?) .select(&:valid?) .sort_by(&:value) .reverse .take(max) else