Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Ruby eventmachine pres @rubybdx

Ruby eventmachine pres @rubybdx

Eventmachine basics. Understand low lovel to avoid mistakes.
More infos on http://www.mathieu-elie.net/eventmachine-introduction-pres-rubybdx-screencast-fr

Avatar for Mathieu Elie

Mathieu Elie

August 08, 2012

Other Decks in Technology

Transcript

  1. EventMachine Components • Reactor • Your code (callbacks) • Tread

    pool (non blocking long running tasks) lundi 15 octobre 12
  2. Reactor • Main loop / Central point • Dispatch call

    to business code (your code) • Single threaded ! lundi 15 octobre 12
  3. Reactor • run-reactor.rb • EM.run block until its stopped •

    its not really blocking, the reactor pattern is running forever ;) lundi 15 octobre 12
  4. Your code • Called by reactor • blocking ! (called

    by a single thread dispatcher aka reactor) lundi 15 octobre 12
  5. Your code • each timer own a callback, like any

    code like network call etc.... • a long running task will block the reactor lundi 15 octobre 12
  6. Tread pool • Pool fixed size ! • Dont block

    the reactor if you have a long running task • use the thread pool ! lundi 15 octobre 12
  7. Tread pool • EM.defer -> run the callback inside on

    thread on the pool thread • Reactor continue to dispatch to other code. nice ! lundi 15 octobre 12
  8. simple server • module implements callbacks: easy ! • see

    the EventMachine.run - > launch the reactor • Inside reactor -> start server :) lundi 15 octobre 12
  9. contact / more infos • http://www.mathieu-elie.net -> tech blog ->

    and all concact infos (github, linkedin, and so on...) • available for freelance • questions ? feel free to mail me :) lundi 15 octobre 12