Skip to content

Commit

Permalink
examples: a scratchy launcher helper
Browse files Browse the repository at this point in the history
  • Loading branch information
niamster committed Feb 22, 2015
1 parent 2834c60 commit d4d5ecf
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 8 deletions.
16 changes: 8 additions & 8 deletions examples/itchy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@

id = 'itchy'

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

opts.on("--id ID", "Assign node ID") do |v|
id = v
end
end.parse!

class Itchy
include Celluloid

Expand Down Expand Up @@ -47,6 +39,14 @@ def work(value)
end

if __FILE__ == $0
OptionParser.new do |opts|
opts.banner = "Usage: itchy.rb [options]"

opts.on("--id ID", "Assign node ID") do |v|
id = v
end
end.parse!

Itchy.supervise_as :itchy
puts "Starting itchy with ID '#{id}'"
DCell.start :id =>id, :registry => registry
Expand Down
13 changes: 13 additions & 0 deletions examples/massive-scratchy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@
require 'dcell'
require_relative 'registry'
require_relative 'itchy'
require 'optparse'

local = true

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
end.parse!

DCell.start :registry => registry
puts "Making itchy work hard everywhere!"
Expand Down Expand Up @@ -56,6 +67,8 @@ def run_test(itchies, method, info, args=[])
run_test itchies, :async, "remote async", repeat
itchies.each {|itchy| itchy.terminate}

exit unless local

itchies = max.times.map {Itchy.new}
run_test itchies, :future, "local futures", repeat
run_test itchies, :async, "local async", repeat
Expand Down
43 changes: 43 additions & 0 deletions examples/scratchy-launcher.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env ruby

require 'optparse'

pids = Array.new
count = 1

args = []
scratchy = 'scratchy.rb'

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

opts.on("--count COUNT", OptionParser::DecimalInteger, "Number of massive-scratchy instances") do |v|
count = v
end
opts.on("--massive", "execute massive scratchy instead of generic") do
args = ['--no-local']
scratchy = 'massive-scratchy.rb'
end
end.parse!

Signal.trap(:INT) do
pids.each do |pid|
begin
Process.kill :TERM, pid if pid
rescue
end
end
end

count.times do |id|
pid = Process.spawn Gem.ruby, File.expand_path("./examples/#{scratchy}"), *args
unless pid
STDERR.print "ERROR: Couldn't start test node."
end
pids << pid
end

start = Time.now
Process.waitall
stop = Time.now
puts "All scratchies completed within #{stop-start} seconds"

0 comments on commit d4d5ecf

Please sign in to comment.