Skip to main content
Threads and
  Events in
Harmony with
  Celluloid
   Kyle Drake
Hi, I’m Kyle Drake. I
work at Geoloqi Esri.

We built a geofencing
           Text


and real-time location
 streaming platform.
Last year, IText a
              did
talk at KRTConf.
I was really into
pure event-driven
           Text
(reactor pattern
based) architecture.
EventMachine,
    Twisted,
    Node.js
• Event-driven
         Text


• No threads
• One CPU core
• Process Spawning
I released
sinatra-synchrony,
so I could use
          Text


EventMachine
without callbacks.
Since then, I’ve
         Text
changed my mind.
I’m really not a fan
of EventMachine
            Text


anymore.
EventMachine is
• A frankenstein - guts the ruby internals
• Not in active development
                         Text
• Makes non-blocking IO block
• Requires special code from Ruby libraries
• Hard to use in an OOP way
• Is really difficult to work with
• Poorly documented
Ruby developers
need to stop using
EventMachine. It’s
           Text


the wrong
direction.
Check this
benchmark
     Text


out:
Text




http://rhaas.blogspot.com/2012/04/did-i-say-32-cores-how-about-64.html
Predictions:
More Cores.
A lot more.
Predictions:
More libraries
      =
more memory
Will process
spawning work
   forever?

  It might.
It might not.

Thousands of
   cores?
Ruby MRI:
Global Interpreter Lock
   (single CPU core)

  Rubinius and JRuby:
    Full threading
 (multiple CPU cores)

~20KB per thread
We’re not finding
 a lot of thread
 safety issues in
      Ruby.
“Threading is
   hard”
Threading is
   not an
 intention!
Let’s fix it by
    abstracting
threads into how
  humans think!
http://celluloid.io
• Developed by Tony Arcieri
• Actor Pattern for Ruby
• Lots of inspiration from Erlang
Each actor is a
concurrent object
running in its own
      thread
First “Killer App”:

     Sidekiq
   Mike Perham
Don’t get me
wrong. Event-
driven is still
 awesome.
“..seasoned engineers are
using a mix of threaded,
event-based, and
alternative concurrency
approaches like Actors”

      - Alex Payne
What if we could
combine threads
  and reactor
 patterns.. and
    actors?!
https://github.com/celluloid/celluloid-io
• One reactor pattern per Celluloid object
• Multiple reactors? No problem!
• Doesn’t mess with code outside of actor
• Utilizes all CPU cores (using JRuby and Rubinius)
• Websockets, messaging systems, your hugely
successful blog
You don't have to
choose between
  threaded and
   evented IO!
Let’s get
distributed.
"I thought of objects being like
     biological cells and/or
   individual computers on a
     network, only able to
 communicate with messages"
           - Alan   Kay
Guess who was really
  into distributed
 network objects?
NeXT experimented
   with distributed
objects in the mid 90s.

NeXT was way ahead
   of its time.
"Objects can message objects transparently
that live on other machines over the network,
    and you don't have to worry about the
networking gunk, and you don't have to worry
  about finding them, and you don't have to
    worry about anything. It's just as if you
  messaged an object that's right next door."

                - Steve Jobs
“Portable Distributed Objects”
https://github.com/celluloid/dcell
 • Objects talk over networks!
 • Uses 0MQ
 • Aware of eachothers’ existence
 • Distributed gossip protocol
 • Web UI
 • In the early stages, very promising
CODE
EXAMPLES!
Help Us
Build This!
Thanks!
 @kyledrake
kyledrake.net