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
510
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
137
6.7k
Elixir and Ecto
vanstee
5
870
Bootstrap
vanstee
8
750
HTTP API Design for iOS Applications
vanstee
11
580
Consensus: An Introduction to Raft
vanstee
22
2.9k
Convergent Replicated Data Types
vanstee
4
710
Pour Over Brewing Method
vanstee
1
320
Map Reduce & Ruby
vanstee
10
740
Other Decks in Programming
See All in Programming
Swiftコンパイラ超入門+async関数の仕組み
shiz
0
180
PHPカンファレンス 2024|共創を加速するための若手の技術挑戦
weddingpark
0
140
為你自己學 Python
eddie
0
530
React 19でお手軽にCSS-in-JSを自作する
yukukotani
5
580
AWS re:Invent 2024個人的まとめ
satoshi256kbyte
0
110
PHPUnitしか使ってこなかった 一般PHPerがPestに乗り換えた実録
mashirou1234
0
440
ドメインイベント増えすぎ問題
h0r15h0
2
580
PicoRubyと暮らす、シェアハウスハック
ryosk7
0
240
ISUCON14感想戦で85万点まで頑張ってみた
ponyo877
1
740
カンファレンス動画鑑賞会のススメ / Osaka.swift #1
hironytic
0
180
Rubyでつくるパケットキャプチャツール
ydah
0
220
chibiccをCILに移植した結果 (NGK2025S版)
kekyo
PRO
0
160
Featured
See All Featured
Dealing with People You Can't Stand - Big Design 2015
cassininazir
365
25k
A Tale of Four Properties
chriscoyier
157
23k
Making the Leap to Tech Lead
cromwellryan
133
9k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
7k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
4
190
Gamification - CAS2011
davidbonilla
80
5.1k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.2k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
45
2.3k
Designing Experiences People Love
moore
139
23k
A Philosophy of Restraint
colly
203
16k
Writing Fast Ruby
sferik
628
61k
The Pragmatic Product Professional
lauravandoore
32
6.4k
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