CelluloidDCell&
View Slide
@vansteegithub.com/vansteePatrick Van Steehighgroove.com
@tarcieriRevactorReianio4rCryptospherecool.io
brew install zeromqgem install dcellSetup
CelluloidGeneral purpose concurrencyframework for Ruby built on theActor Model
class Counterattr_reader :countdef initialize@count = 0enddef increment@count += 1endend
class Counterattr_reader :countdef initialize@count = 0@mutex = Mutex.newenddef increment@mutex.synchronize do@count += 1endendend
Threadsarehard!
class Counterinclude Celluloidattr_reader :countdef initialize@count = 0enddef increment@count += 1endend
ActorModel
•No shared state•Communicate withmessages•Process messagessequentially
class Counterinclude Celluloiddef increment(count, actor)return count if count < 10000actor.increment(count + 1,Actor.current)endend
&AsynchronousMethod CallsFutures
counter = Counter.new# returns immediatelycounter.increment!puts counter.count# returns immediatelyfuture = counter.future :incrementputs future.value
module Enumerabledef map(&block)futures = map do |item|Celluloid::Future.new(item,&block)endfutures.map(&:value)endend
Caveats
• The GIL in MRI doesnot allow parallelism• Threads and Fibersare expensive• Concurrency is still ahard problem[not really]
DCell
CelluloidGeneral purpose concurrencyframework for Ruby built on theActor ModelDCellDistributed Celluloid over 0MQ
“I thought of objects being likebiological cells or individualcomputers on a network, onlyable to communicate withmessages. Alan Kay
• Exposes Actors on theNetwork• Send messages as younormally would
DRb DCellThreads Actors
Demo
AlsoCheckoutSidekiq
github.comcelluloid/celluloidcelluloid/dcell
Hack Night