Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Celluloid & DCell
Search
Patrick Van Stee
July 11, 2012
Programming
4
410
Celluloid & DCell
Patrick Van Stee
July 11, 2012
Tweet
Share
More Decks by Patrick Van Stee
See All by Patrick Van Stee
Raft: Consensus for Rubyists
vanstee
133
6.3k
Elixir and Ecto
vanstee
5
740
Bootstrap
vanstee
8
680
HTTP API Design for iOS Applications
vanstee
11
500
Consensus: An Introduction to Raft
vanstee
22
2.6k
Convergent Replicated Data Types
vanstee
4
610
Pour Over Brewing Method
vanstee
1
250
Map Reduce & Ruby
vanstee
10
630
Other Decks in Programming
See All in Programming
Exploring Type-Informed Lint Rules in Rust based TypeScript Linters
unvalley
3
610
Apache Hive 4 on Treasure Data
ryukobayashi
1
480
TypeScriptコードの漸進的改善 / Progressive Improvement of TypeScript Code
medley
1
400
AmperとFleetを使ったAndroidアプリ
yoppie
0
300
Jetpack Composeとデザインシステム
rmakiyama
0
220
Fast JSX: Don't clone props object #28768
yossydev
1
230
哲学史とモデリング
tanakahisateru
2
380
Direct Style Effect Systems The Print[A] ExampleA Comprehension Aid
philipschwarz
PRO
0
400
Open standards for building event-driven applications in the cloud
meteatamel
0
210
Prepare for Jakarta EE 11 - Performance and Developer Productivity
ivargrimstad
0
120
Timeline エディター拡張入門
yucchiy
0
440
TypeScriptから始める VR生活
tamagokakeg
2
110
Featured
See All Featured
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
8
3.5k
The Straight Up "How To Draw Better" Workshop
denniskardys
228
130k
Faster Mobile Websites
deanohume
300
30k
Producing Creativity
orderedlist
PRO
338
39k
Principles of Awesome APIs and How to Build Them.
keavy
121
16k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
34
6.1k
Typedesign – Prime Four
hannesfritz
36
2.1k
Designing on Purpose - Digital PM Summit 2013
jponch
111
6.5k
Six Lessons from altMBA
skipperchong
22
3k
Designing for Performance
lara
601
67k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
155
14k
Embracing the Ebb and Flow
colly
80
4.2k
Transcript
Celluloid DCell &
@vanstee github.com/vanstee Patrick Van Stee highgroove.com
@tarcieri Revactor Reia nio4r Cryptosphere cool.io
brew install zeromq gem install dcell Setup
Celluloid General purpose concurrency framework for Ruby built on the
Actor Model
class Counter attr_reader :count def initialize @count = 0 end
def increment @count += 1 end end
class Counter attr_reader :count def initialize @count = 0 @mutex
= Mutex.new end def increment @mutex.synchronize do @count += 1 end end end
Threads are hard!
class Counter include Celluloid attr_reader :count def initialize @count =
0 end def increment @count += 1 end end
Actor Model
•No shared state •Communicate with messages •Process messages sequentially
class Counter include Celluloid def increment(count, actor) return count if
count < 10000 actor.increment( count + 1, Actor.current ) end end
& Asynchronous Method Calls Futures
counter = Counter.new # returns immediately counter.increment! puts counter.count #
returns immediately future = counter.future :increment puts future.value
module Enumerable def map(&block) futures = map do |item| Celluloid::Future.new(
item, &block ) end futures.map(&:value) end end
Caveats
• The GIL in MRI does not allow parallelism •
Threads and Fibers are expensive • Concurrency is still a hard problem [not really]
DCell
Celluloid General purpose concurrency framework for Ruby built on the
Actor Model DCell Distributed Celluloid over 0MQ
“I thought of objects being like biological cells or individual
computers on a network, only able to communicate with messages. Alan Kay
• Exposes Actors on the Network • Send messages as
you normally would
DRb DCell Threads Actors
Demo
Also Checkout Sidekiq
github.com celluloid/celluloid celluloid/dcell
Hack Night