lib/zold/stress/round.rb in zold-stress-0.5.1 vs lib/zold/stress/round.rb in zold-stress-0.5.2
- old
+ new
@@ -24,10 +24,11 @@
require 'parallelize'
require 'zold/key'
require 'zold/id'
require 'zold/commands/push'
require 'zold/commands/remote'
+require 'zold/commands/list'
require_relative 'stats'
require_relative 'pool'
require_relative 'pmnts'
require_relative 'air'
@@ -37,11 +38,11 @@
# License:: MIT
module Zold::Stress
# Full round of stress test
class Round
def initialize(pvt:, wallets:, remotes:, copies:,
- stats:, air:, opts:, log: Zold::Log::Quiet.new, vlog: Zold::Log::Quiet.new)
+ stats:, air:, opts:, log: Zold::Log::NULL, vlog: Zold::Log::NULL)
@pvt = pvt
@wallets = wallets
@remotes = remotes
@copies = copies
@opts = opts
@@ -49,10 +50,14 @@
@stats = stats
@air = air
@vlog = vlog
end
+ def list
+ Zold::List.new(wallets: @wallets, copies: @copies, log: @log).run(['list'] + @opts.arguments)
+ end
+
def update
start = Time.now
cmd = Zold::Remote.new(remotes: @remotes, log: @vlog)
args = ['remote'] + @opts.arguments
cmd.run(args + ['trim'])
@@ -72,10 +77,11 @@
remotes: @remotes, copies: @copies, stats: @stats,
log: @log, opts: @opts, vlog: @vlog
)
pool.rebuild
@wallets.all.peach(@opts['threads']) do |id|
+ Thread.current.name = 'prepare-push'
@stats.exec('push') do
Zold::Push.new(wallets: @wallets, remotes: @remotes, log: @vlog).run(
['push', id.to_s, "--network=#{@opts['network']}"] + @opts.arguments
)
end
@@ -93,10 +99,11 @@
log: @log, opts: @opts, vlog: @vlog
).send
mutex = Mutex.new
sources = sent.group_by { |p| p[:source] }
sources.peach(@opts['threads']) do |a|
+ Thread.current.name = 'send-push'
@stats.exec('push') do
Zold::Push.new(wallets: @wallets, remotes: @remotes, log: @vlog).run(
['push', a[0].to_s, "--network=#{@opts['network']}"] + @opts.arguments
)
mutex.synchronize do
@@ -107,20 +114,21 @@
end
@log.info("#{sent.count} payments for #{sent.map { |s| s[:amount] }.inject(&:+)} \
sent from #{sources.count} wallets, \
in #{Zold::Age.new(start)}, #{@air.fetch.count} are now in the air, \
#{Zold::Age.new(@air.fetch.map { |a| a[:pushed] }.reverse[0] || Time.now)} is the oldest")
- @log.debug(" #{sent.map { |p| "#{p[:source]} -> #{p[:target]} #{p[:amount]}" }.join("\n ")}")
+ @log.debug(sent.map { |p| "#{p[:source]} -> #{p[:target]} #{p[:amount]}" }.join("\n"))
end
def pull
start = Time.now
targets = @air.fetch.group_by { |p| p[:target] }.map { |a| a[0] }
targets.peach(@opts['threads']) do |id|
+ Thread.current.name = "pull-#{id}"
@stats.exec('pull') do
Zold::Pull.new(wallets: @wallets, remotes: @remotes, copies: @copies, log: @vlog).run(
- ['pull', id.to_s, "--network=#{@opts['network']}"] + @opts.arguments
+ ['pull', id.to_s, "--network=#{@opts['network']}", '--skip-propagate'] + @opts.arguments
)
end
@air.pulled(id)
@stats.put('input', @wallets.acq(id, &:size))
end
@@ -132,14 +140,14 @@
total = 0
@air.fetch.each do |p|
next unless @wallets.acq(p[:target], &:exists?)
t = @wallets.acq(p[:target], &:txns).find { |x| x.details == p[:details] && x.bnf == p[:source] }
next if t.nil?
+ @air.arrived(p)
@stats.put('arrived', p[:pulled] - p[:pushed])
total += 1
@log.debug("#{p[:amount]} arrived from #{p[:source]} to #{p[:target]} \
in txn ##{t.id} in #{Zold::Age.new(p[:start])}: #{t.details}")
- @air.delete(p)
end
@log.info("#{total} payments just arrived, #{@air.fetch.count} still in the air")
end
end
end