Skip to content

Commit

Permalink
examples: launch multiple itchy instances within one process
Browse files Browse the repository at this point in the history
  • Loading branch information
niamster committed Feb 24, 2015
1 parent 196c724 commit 2b80988
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 7 deletions.
22 changes: 20 additions & 2 deletions examples/itchy-launcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,21 @@

pids = Array.new
count = 1
threaded = false
mass = false

OptionParser.new do |opts|
opts.banner = "Usage: itchy-launcher.rb [options]"

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
Expand All @@ -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
16 changes: 14 additions & 2 deletions examples/itchy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 6 additions & 2 deletions examples/massive-scratchy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
require 'optparse'

local = true
actor = :itchy

OptionParser.new do |opts|
opts.banner = "Usage: massive-scratchy.rb [options]"

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
Expand Down Expand Up @@ -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}
Expand Down
8 changes: 7 additions & 1 deletion examples/scratchy-launcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

pids = Array.new
count = 1
indexed = false

args = []
scratchy = 'scratchy.rb'
Expand All @@ -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'
Expand All @@ -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
Expand Down

0 comments on commit 2b80988

Please sign in to comment.