Link
Embed
Share
Beginning
This slide
Copy link URL
Copy link URL
Copy iframe embed code
Copy iframe embed code
Copy javascript embed code
Copy javascript embed code
Share
Tweet
Share
Tweet
Slide 1
Slide 1 text
Celluloid DCell &
Slide 2
Slide 2 text
@vanstee github.com/vanstee Patrick Van Stee highgroove.com
Slide 3
Slide 3 text
@tarcieri Revactor Reia nio4r Cryptosphere cool.io
Slide 4
Slide 4 text
brew install zeromq gem install dcell Setup
Slide 5
Slide 5 text
Celluloid General purpose concurrency framework for Ruby built on the Actor Model
Slide 6
Slide 6 text
class Counter attr_reader :count def initialize @count = 0 end def increment @count += 1 end end
Slide 7
Slide 7 text
class Counter attr_reader :count def initialize @count = 0 @mutex = Mutex.new end def increment @mutex.synchronize do @count += 1 end end end
Slide 8
Slide 8 text
Threads are hard!
Slide 9
Slide 9 text
class Counter include Celluloid attr_reader :count def initialize @count = 0 end def increment @count += 1 end end
Slide 10
Slide 10 text
Actor Model
Slide 11
Slide 11 text
•No shared state •Communicate with messages •Process messages sequentially
Slide 12
Slide 12 text
class Counter include Celluloid def increment(count, actor) return count if count < 10000 actor.increment( count + 1, Actor.current ) end end
Slide 13
Slide 13 text
& Asynchronous Method Calls Futures
Slide 14
Slide 14 text
counter = Counter.new # returns immediately counter.increment! puts counter.count # returns immediately future = counter.future :increment puts future.value
Slide 15
Slide 15 text
module Enumerable def map(&block) futures = map do |item| Celluloid::Future.new( item, &block ) end futures.map(&:value) end end
Slide 16
Slide 16 text
Caveats
Slide 17
Slide 17 text
• The GIL in MRI does not allow parallelism • Threads and Fibers are expensive • Concurrency is still a hard problem [not really]
Slide 18
Slide 18 text
DCell
Slide 19
Slide 19 text
Celluloid General purpose concurrency framework for Ruby built on the Actor Model DCell Distributed Celluloid over 0MQ
Slide 20
Slide 20 text
“I thought of objects being like biological cells or individual computers on a network, only able to communicate with messages. Alan Kay
Slide 21
Slide 21 text
• Exposes Actors on the Network • Send messages as you normally would
Slide 22
Slide 22 text
DRb DCell Threads Actors
Slide 23
Slide 23 text
Demo
Slide 24
Slide 24 text
Also Checkout Sidekiq
Slide 25
Slide 25 text
github.com celluloid/celluloid celluloid/dcell
Slide 26
Slide 26 text
Hack Night