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
670
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
620
Other Decks in Programming
See All in Programming
Scalable Customer Journey Orchestration (CJO)
lewuathe
0
420
Deep Dive into React Stream/Serialize
mugi_uno
3
670
What We Can Learn From OSS
inouehi
0
440
雑に思考を整理する技術と効能
konifar
63
30k
ServerAction で Progressive Enhancement はどこまで頑張れるか? / progressive-enhancement-with-server-action
takefumiyoshii
6
420
#phpcon_odawara オープン・クローズドなテストフィクスチャを求めて / open closed test fixtures
77web
3
240
業務ツールとして使うPostman
msys75
0
100
AmperとFleetを使ったAndroidアプリ
yoppie
0
250
Sheets API使ってみた
toshi0383
2
160
PHPはいつから死んでいるかの調査
chiroruxx
2
420
Ruby Function Composition
bkuhlmann
1
340
スキーマ駆動開発による品質とスピードの両立 - 私達は何故、スキーマを書くのか
kentaroutakeda
0
180
Featured
See All Featured
It's Worth the Effort
3n
180
27k
Building Effective Engineering Teams - LeadDev
addyosmani
31
1.9k
Unsuck your backbone
ammeep
663
57k
Producing Creativity
orderedlist
PRO
338
39k
5 minutes of I Can Smell Your CMS
philhawksworth
199
19k
Gamification - CAS2011
davidbonilla
77
4.6k
Designing Experiences People Love
moore
136
23k
Embracing the Ebb and Flow
colly
80
4.2k
Why Our Code Smells
bkeepers
PRO
331
56k
10 Git Anti Patterns You Should be Aware of
lemiorhan
649
58k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
79
43k
A Philosophy of Restraint
colly
197
16k
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