diff --git a/examples/itchy-launcher.rb b/examples/itchy-launcher.rb new file mode 100755 index 0000000..c9e51bc --- /dev/null +++ b/examples/itchy-launcher.rb @@ -0,0 +1,33 @@ +#!/usr/bin/env ruby + +require 'optparse' + +pids = Array.new +count = 1 + +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 +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/itchy.rb"), "--id", "itchy-#{Process.pid}-#{id}" + unless pid + STDERR.print "ERROR: Couldn't start test node." + end + pids << pid +end + +Process.waitall diff --git a/examples/itchy.rb b/examples/itchy.rb index 41491f6..1db1002 100755 --- a/examples/itchy.rb +++ b/examples/itchy.rb @@ -1,7 +1,19 @@ #!/usr/bin/env ruby + require 'dcell' +require 'optparse' require_relative 'registry' +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 @@ -19,9 +31,18 @@ def fight end @n end + + def work(value) + res = 0 + 10000.times do + res += Math.log2(value + 1) + end + res + end end Itchy.supervise_as :itchy -DCell.start :id => "itchy", :registry => registry +puts "Starting itchy with ID '#{id}'" +DCell.start :id =>id, :registry => registry sleep diff --git a/examples/massive-scratchy.rb b/examples/massive-scratchy.rb new file mode 100755 index 0000000..fbb40a7 --- /dev/null +++ b/examples/massive-scratchy.rb @@ -0,0 +1,23 @@ +#!/usr/bin/env ruby +require 'dcell' +require_relative 'registry' + +DCell.start :registry => registry + +itchies = DCell[:itchy].cycle +puts "Making itchy work hard everywhere!" + +start = Time.now +futures = Array.new +1000.times do |i| + itchy = itchies.next + futures << itchy.future.work(i) +end + +res = 0 +futures.each do |f| + res += f.value +end +puts "Test result #{res}" +stop = Time.now +puts "Test executed at #{stop-start}"