Skip to content

Instantly share code, notes, and snippets.

@cheald
Last active January 4, 2016 13:09
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/8626163 to your computer and use it in GitHub Desktop.
Save cheald/8626163 to your computer and use it in GitHub Desktop.
require 'celluloid'
$count = 0
$start = Time.now.to_f
class FooActor
include Celluloid
def listen
while true do
x = Celluloid::Actor[:bar_actor_pool]
x.async.do_stuff if x
sleep 0.05
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> - %2.1f/s" % [self.object_id, Thread.current.object_id, rate]
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].async.listen }
sleep
jruby --1.9 --server --manage -J-Djava.rmi.server.hostname=luna -J-Dcom.sun.management.jmxremote -J-Dcom.sun.management.jmxremote.port=12998 -J-Dcom.sun.management.jmxremote.authenticate=false -J-Dcom.sun.management.jmxremote.ssl=false -J-Djava.security.policy=$JAVA_HOME/bin/jstatd.all.policy -J-Dcom.sun.management.jmxremote.local.only=false -J-Djruby.thread.pooling=true fibers.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment