From 2b809886c9ed7c9a1d077c24d855a24d72854a82 Mon Sep 17 00:00:00 2001 From: Dmytro Milinevskyy Date: Tue, 24 Feb 2015 00:51:26 +0100 Subject: [PATCH] examples: launch multiple itchy instances within one process --- examples/itchy-launcher.rb | 22 ++++++++++++++++++++-- examples/itchy.rb | 16 ++++++++++++++-- examples/massive-scratchy.rb | 8 ++++++-- examples/scratchy-launcher.rb | 8 +++++++- 4 files changed, 47 insertions(+), 7 deletions(-) diff --git a/examples/itchy-launcher.rb b/examples/itchy-launcher.rb index c9e51bc..59f7c99 100755 --- a/examples/itchy-launcher.rb +++ b/examples/itchy-launcher.rb @@ -4,6 +4,8 @@ pids = Array.new count = 1 +threaded = false +mass = false OptionParser.new do |opts| opts.banner = "Usage: itchy-launcher.rb [options]" @@ -11,6 +13,12 @@ opts.on("--count COUNT", OptionParser::DecimalInteger, "Number of itchy instances") do |v| count = v end + opts.on("--threaded", "Start itchy with many actors") do + threaded = true + end + opts.on("--mass", "Start many itchies with many actors") do + mass = true + end end.parse! Signal.trap(:INT) do @@ -22,12 +30,22 @@ end end -count.times do |id| - pid = Process.spawn Gem.ruby, File.expand_path("./examples/itchy.rb"), "--id", "itchy-#{Process.pid}-#{id}" +def spawn_itchy(pids, args) + pid = Process.spawn Gem.ruby, File.expand_path("./examples/itchy.rb"), *args unless pid STDERR.print "ERROR: Couldn't start test node." end pids << pid end +if threaded and not mass + spawn_itchy pids, ["--count", "#{count}"] +else + count.times do |id| + pargs = ["--id", "itchy-#{Process.pid}-#{id}"] + pargs += ["--count", "#{count}"] if threaded + spawn_itchy pids, pargs + end +end + Process.waitall diff --git a/examples/itchy.rb b/examples/itchy.rb index f974b2b..5fd4d68 100755 --- a/examples/itchy.rb +++ b/examples/itchy.rb @@ -39,16 +39,28 @@ def work(value) end if __FILE__ == $0 + count = 1 OptionParser.new do |opts| opts.banner = "Usage: itchy.rb [options]" opts.on("--id ID", "Assign node ID") do |v| id = v end + opts.on("--count COUNT", OptionParser::DecimalInteger, "Number of itchy actors") do |v| + count = v + end end.parse! - Itchy.supervise_as :itchy - puts "Starting itchy with ID '#{id}'" + if count == 1 + Itchy.supervise_as :itchy + puts "Starting :itchy with ID '#{id}'" + else + count.times do |idx| + name = "itchy-#{idx}".to_sym + Itchy.supervise_as name + puts "Starting #{name} with ID '#{id}'" + end + end DCell.start :id =>id, :registry => registry sleep end diff --git a/examples/massive-scratchy.rb b/examples/massive-scratchy.rb index d6ea1ad..7f6c633 100755 --- a/examples/massive-scratchy.rb +++ b/examples/massive-scratchy.rb @@ -5,6 +5,7 @@ require 'optparse' local = true +actor = :itchy OptionParser.new do |opts| opts.banner = "Usage: massive-scratchy.rb [options]" @@ -12,6 +13,9 @@ opts.on("--no-local", "Do not run local celluloid actor tests") do local = false end + opts.on("--actor ACTOR", "Actor name to stress") do |a| + actor = a.to_sym + end end.parse! DCell.start :registry => registry @@ -59,10 +63,10 @@ def run_test(itchies, method, info, args=[]) Celluloid.logger = nil -max = DCell[:itchy].count +max = DCell[actor].count repeat = 1000 -itchies = DCell[:itchy] +itchies = DCell[actor] run_test itchies, :future, "remote futures", repeat run_test itchies, :async, "remote async", repeat itchies.each {|itchy| itchy.terminate} diff --git a/examples/scratchy-launcher.rb b/examples/scratchy-launcher.rb index fcfdf74..3030908 100755 --- a/examples/scratchy-launcher.rb +++ b/examples/scratchy-launcher.rb @@ -4,6 +4,7 @@ pids = Array.new count = 1 +indexed = false args = [] scratchy = 'scratchy.rb' @@ -14,6 +15,9 @@ opts.on("--count COUNT", OptionParser::DecimalInteger, "Number of massive-scratchy instances") do |v| count = v end + opts.on("--indexed", "Connect to itchy actor with index") do + indexed = true + end opts.on("--massive", "execute massive scratchy instead of generic") do args = ['--no-local'] scratchy = 'massive-scratchy.rb' @@ -30,7 +34,9 @@ end count.times do |id| - pid = Process.spawn Gem.ruby, File.expand_path("./examples/#{scratchy}"), *args + pargs = args + pargs += ["--actor", "itchy-#{id}"] if indexed + pid = Process.spawn Gem.ruby, File.expand_path("./examples/#{scratchy}"), *pargs unless pid STDERR.print "ERROR: Couldn't start test node." end