Skip to content

Instantly share code, notes, and snippets.

@cheald
Created January 30, 2014 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cheald/8716314 to your computer and use it in GitHub Desktop.
Save cheald/8716314 to your computer and use it in GitHub Desktop.
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