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
620
Other Decks in Programming
See All in Programming
DMMプラットフォームがTiDB Cloudを採用した背景
pospome
9
4.3k
Native Federation: The Future of Micro Frontends in Angular
manfredsteyer
PRO
0
120
Milestoner
bkuhlmann
1
420
“Seeing Like a Programmer”—Resiliency, Limits, and Moral Hazards in Software Engineering (LambdaConf 2024)
chriskrycho
0
220
検証も兼ねて個人開発でHonoとかと向き合った話
hanetsuki
1
1.4k
Three ways to use AI on Android: The Good, the Bad and the Ugly
marxallski
0
110
MetricKitで予期せぬ終了を検知する話 / Detect unexpected termination with MetricKit
nekowen
1
200
slow types ってなんだろう?
karad
0
140
Code Reviews
bkuhlmann
4
900
if constexpr文はテンプレート世界のラムダ式である
faithandbrave
3
690
Elm Form Validation
bkuhlmann
0
520
VS Code をプロダクトにどう取り込むか
onomax
1
770
Featured
See All Featured
Typedesign – Prime Four
hannesfritz
36
2.1k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
18
6.9k
The Art of Programming - Codeland 2020
erikaheidi
43
12k
Fashionably flexible responsive web design (full day workshop)
malarkey
398
65k
Ruby is Unlike a Banana
tanoku
96
10k
The Mythical Team-Month
searls
217
42k
VelocityConf: Rendering Performance Case Studies
addyosmani
321
23k
5 minutes of I Can Smell Your CMS
philhawksworth
199
19k
A designer walks into a library…
pauljervisheath
201
23k
Designing the Hi-DPI Web
ddemaree
276
33k
A Modern Web Designer's Workflow
chriscoyier
689
190k
The Invisible Side of Design
smashingmag
294
49k
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