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

Letting Concurrency Help You Today

Richard B
November 18, 2014

Letting Concurrency Help You Today

Ruby has never been renowned for its performance. We choose to love Ruby for its more admirable traits, like simplicity and expressiveness. But it turns out that we can have the best of both worlds by kicking the single-threaded model to the curb and using tried and true concurrency abstractions.

We will take a look at the building blocks Ruby offers for concurrency and how Rubyists have used these to build scalable, performant libraries just dying to be used. You’ll walk away with an understanding of concurrency and how you can leverage it in your applications today.

Richard B

November 18, 2014
Tweet

More Decks by Richard B

Other Decks in Programming

Transcript

  1. WHY SHOULD I CARE? •Get more out of hardware •Better

    user experience •Better design (say what?)
  2. “Concurrency is about dealing with lots of things at once.

    Parallelism is about doing lots of things at once.” ! - Rob Pike
  3. ?

  4. A REAL RUBY EXAMPLE PARALLEL ! Example: Threaded or forking

    web server on multicore. ! No communication between the requests. ! Points of execution overlapping the same time. CONCURRENT ! Example: Batch processing background jobs. ! Communication between jobs or another job ! Multiple points of execution.
  5. CPU I/O COMM. PROCESSES ✓ ✓ IPC THREADS ✓ ✓

    SHARED MEMORY EVENTS ✓ ??? Ask Node.js
  6. Basics Recap • Composition & Communication • Concurrency is structure

    • Parallelism is execution and time • Processes, Threads, Events
  7. ???

  8. ! ! ! ! class Greeter! !! ! ! include

    Celluloid! ! !! ! ! def greet(msg)! ! ! ! ! puts msg! !! ! ! end! ! ! ! ! end! ! greeter = Greeter.new! => #<Celluloid::CellProxy(Greeter)>! ! greeter.async! => #<Celluloid::AsyncProxy(Greeter)>! ! greeter.async.greet("Hello, Ruby Conf!”)
  9. module Celluloid! class AsyncProxy < AbstractProxy! ! def method_missing(meth, *args,

    &block)! ! ! ! ...! @mailbox << AsyncCall.new(meth, args, block)! end! end! end!
  10. 1990s PL Design Step One Pick a paradigm Step Two

    Static or dynamic? … Step 185 Slap some POSIX Threads on!*
  11. 2000s PL Design Step One Choose a concurrency model Step

    2-∞ Choose features that compliment step #1