Skip to content

Instantly share code, notes, and snippets.

@jraines
Created May 19, 2011 17:43
Show Gist options
  • Save jraines/981313 to your computer and use it in GitHub Desktop.
Save jraines/981313 to your computer and use it in GitHub Desktop.
EventMachine intro

Don't block the reactor loop

Use blocks as callbacks

Use async libraries

EM.start_server('0.0.0.0', 1337, ChatClient)

Instance variables keep state on a per Connection basis

Non-idiomatic ruby

  callbacks { within { callbacks } } 

EventMachine is good for web services

Linux: use .epoll

Check wiki for EM aware gems

Use em-hiredis

JRuby threads work much better -- apps needing concurrency should use

Multithreaded code = hard

Many Rails features not thread safe, such as autoload

Enter Actors

  • pass messages, don't share state
  • allows lock-free concurrency
  • See Erlang, Scala

Check out girl_friday gem

Testing: em-spec

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment