Skip to content

Commit

Permalink
examples: do a comparison between local and remote invocation of actors
Browse files Browse the repository at this point in the history
  • Loading branch information
niamster committed Feb 12, 2015
1 parent 06471f8 commit c2498a6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
15 changes: 8 additions & 7 deletions examples/itchy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,17 @@ def fight
def work(value)
@n += 1
res = 0
10000.times do
res += Math.log2(value + 1)
100000.times do
res += (value + 1) ** 2
end
@res += res
res
end
end
Itchy.supervise_as :itchy

puts "Starting itchy with ID '#{id}'"
DCell.start :id =>id, :registry => registry

sleep
if __FILE__ == $0
Itchy.supervise_as :itchy
puts "Starting itchy with ID '#{id}'"
DCell.start :id =>id, :registry => registry
sleep
end
33 changes: 24 additions & 9 deletions examples/massive-scratchy.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env ruby
require 'dcell'
require_relative 'registry'
require_relative 'itchy'

DCell.start :registry => registry
puts "Making itchy work hard everywhere!"
Expand All @@ -16,36 +17,50 @@ def count(itchies)
itchies.reduce(0) {|sum, itchy| sum + itchy.n}
end

def test_future(itchies)
def test_future(itchies, repeat)
futures = Array.new
barrel = itchies.cycle
1000.times do |i|
repeat.times do |i|
itchy = barrel.next
futures << itchy.future.work(i)
end
futures.reduce(0) {|sum, f| sum + f.value}
end

def test_async(itchies)
def test_async(itchies, repeat)
barrel = itchies.cycle
1000.times do |i|
repeat.times do |i|
itchy = barrel.next
itchy.async.work(i)
end
itchies.reduce(0) {|sum, itchy| sum + itchy.res}
end

def run_test(itchies, name, args=[])
puts "Running test: #{name}"
def run_test(itchies, method, info, args=[])
puts "Running test: #{info}"
reset itchies
start = Time.now
res = send "test_#{name}".to_sym, itchies, *args
res = send "test_#{method}".to_sym, itchies, *args
stop = Time.now
puts "Test result #{res}, count #{count itchies}"
puts "Test executed within #{stop-start}"
end

Celluloid.logger = nil

max = DCell[:itchy].count
repeat = 1000

itchies = DCell[:itchy]
run_test itchies, :future, "remote futures", repeat
run_test itchies, :async, "remote async", repeat
itchies.each {|itchy| itchy.terminate}

itchies = max.times.map {Itchy.new}
run_test itchies, :future, "local futures", repeat
run_test itchies, :async, "local async", repeat
itchies.each {|itchy| itchy.terminate}

run_test itchies, "future"
run_test itchies, "async"
itchies = Itchy.pool size: max
run_test [itchies], :future, "local futures in pool", repeat
itchies.terminate

0 comments on commit c2498a6

Please sign in to comment.