Created
January 30, 2014 19:01
-
-
Save cheald/8716314 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'celluloid' | |
$count = 0 | |
$start = Time.now.to_f | |
$complete = 0 | |
# Celluloid.task_class = Celluloid::TaskPooledFiber | |
class FooActor | |
include Celluloid | |
def listen | |
1000.times do | |
x = Celluloid::Actor[:bar_actor_pool] | |
x.async.do_stuff if x | |
end | |
end | |
end | |
class BarActor | |
include Celluloid | |
def do_stuff | |
$count += 1 | |
rate = $count.to_f / (Time.now.to_f - $start) | |
# puts "%s <Thread %s> <Fiber %s> - %2.1f/s" % [self.object_id, Thread.current.object_id, Fiber.current.inspect, rate] | |
p $count | |
finish if $count >= 4950 | |
end | |
def finish | |
puts "Finished in #{Time.now.to_f - $start} seconds" | |
Celluloid.shutdown if $count == 5000 | |
end | |
end | |
class FooSupervisor < Celluloid::SupervisionGroup | |
pool BarActor, as: "bar_actor_pool", size: 5 | |
pool FooActor, as: "foo_actor_pool", size: 5 | |
end | |
puts "Running..." | |
FooSupervisor.run! | |
5.times { Celluloid::Actor[:foo_actor_pool].listen } | |
sleep |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment