Celluloid & DCell

Celluloid & DCell

B6a8f005f39d23ffc930508ac9da68b9?s=128

Patrick Van Stee

July 11, 2012
Tweet

Transcript

  1. Celluloid DCell &

  2. @vanstee github.com/vanstee Patrick Van Stee highgroove.com

  3. @tarcieri Revactor Reia nio4r Cryptosphere cool.io

  4. brew install zeromq gem install dcell Setup

  5. Celluloid General purpose concurrency framework for Ruby built on the

    Actor Model
  6. class Counter attr_reader :count def initialize @count = 0 end

    def increment @count += 1 end end
  7. class Counter attr_reader :count def initialize @count = 0 @mutex

    = Mutex.new end def increment @mutex.synchronize do @count += 1 end end end
  8. Threads are hard!

  9. class Counter include Celluloid attr_reader :count def initialize @count =

    0 end def increment @count += 1 end end
  10. Actor Model

  11. •No shared state •Communicate with messages •Process messages sequentially

  12. class Counter include Celluloid def increment(count, actor) return count if

    count < 10000 actor.increment( count + 1, Actor.current ) end end
  13. & Asynchronous Method Calls Futures

  14. counter = Counter.new # returns immediately counter.increment! puts counter.count #

    returns immediately future = counter.future :increment puts future.value
  15. module Enumerable def map(&block) futures = map do |item| Celluloid::Future.new(

    item, &block ) end futures.map(&:value) end end
  16. Caveats

  17. • The GIL in MRI does not allow parallelism •

    Threads and Fibers are expensive • Concurrency is still a hard problem [not really]
  18. DCell

  19. Celluloid General purpose concurrency framework for Ruby built on the

    Actor Model DCell Distributed Celluloid over 0MQ
  20. “I thought of objects being like biological cells or individual

    computers on a network, only able to communicate with messages. Alan Kay
  21. • Exposes Actors on the Network • Send messages as

    you normally would
  22. DRb DCell Threads Actors

  23. Demo

  24. Also Checkout Sidekiq

  25. github.com celluloid/celluloid celluloid/dcell

  26. Hack Night