-
-
Notifications
You must be signed in to change notification settings - Fork 271
Frequently Asked Questions
A: If you build a program entirely with Celluloid actors that are running in their own threads, there may be nothing for Ruby's main thread to do. However, the way Ruby is designed, if the main thread exits, all the background threads exit.
The simplest thing to do is to simply sleep the main thread, which allows all of the Celluloid actors to continue to run:
sleepYou can also run one of your actors in the foreground by calling the run method on its class, passing it all the arguments you'd ordinarily pass to new:
MyClass.runHowever, a better solution is to leverage Celluloid's supervision tree feature, and build a [Celluloid::SupervisionGroup](Supervision Groups) whose watchdog you can run in the foreground. Instead of just sleeping the main thread, you can define the toplevel group of a supervision tree as a class, then do:
MyGroup.runwhich will run the toplevel supervisor for your application in the main thread.
A: Celluloid.logger = nil (although you should probably at least consider logging to a file)
See also Logging.
A: finalizer :time_to_go in your Actor class will make Celluloid call that instance method on your actor during shutdown.
See also Finalizers.
A: Celluloid.exception_handler { |ex| MyNotifier.notify(ex) }
A: abort MyException.new("you f'd up, not me!")
Q: I'm trying to create 2000+ actors on OS X and I'm getting a "Cannot allocate memory" error. What do I do?
A: Install Linux, problem solved? ;) Seriously though, OS X has some built-in limitations on how many threads you can create and there's no workaround available at present, sorry.
Q: Can I do blocking I/O inside an actor? (or do I have to use Celluloid::IO)
A: YES, you can do blocking I/O (or any other type of blocking operation) inside an actor, even if it requires native extensions (e.g. DB drivers). All actors run inside their own thread, so making blocking calls will only block that actor, not every actor in the system. Once the blocking I/O operation completes, the actor will resume processing its mailbox, and respond to any pending requests. However, you should still avoid making indefinite blocking calls, e.g. accepting from a listener socket, without using Celluloid::IO, as this can potentially lead to deadlocks. Celluloid::IO is also useful if you want to service many sockets with a single actor.
A: Please see the notes on FiberStackErrors
Always feel free to:
- Visit the
#celluloidchannel on freenode. - Post a bug report or feature request.
- Ask questions on our mailing list.