Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
Celluloid & DCell
Patrick Van Stee
July 11, 2012
Programming
4
280
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
127
5.5k
Elixir and Ecto
vanstee
4
570
Bootstrap
vanstee
8
540
HTTP API Design for iOS Applications
vanstee
11
380
Consensus: An Introduction to Raft
vanstee
22
2.1k
Convergent Replicated Data Types
vanstee
4
460
Pour Over Brewing Method
vanstee
1
130
Map Reduce & Ruby
vanstee
10
500
Other Decks in Programming
See All in Programming
2022年のモダンCSS改
tonkotsuboy_com
24
17k
Rust、何もわからない...#3
estie
0
160
Now in Android Overview
aosa4054
0
400
Rector, time to refactor your code easily
guikingone
2
150
Google I/O 2022 Android関連概要 / Google I/O 2022 Android summary
phicdy
0
390
モデルの定義に基づくバリデーションを実現するためのpydantic入門
daikikatsuragawa
0
120
WindowsコンテナDojo: 第4回 Red Hat OpenShift Localを使ってみよう
oniak3ibm
PRO
0
190
WindowsコンテナDojo:第6回 Red Hat OpenShift入門
oniak3ibm
PRO
0
180
僕が便利だと感じる Snow Monkey の特徴/20220723_Gifu_WordPress_Meetup
oleindesign
0
110
2022 - COSCUP - 打造高速 Ruby 專案開發流程
elct9620
0
100
SAM × Dockerでサーバーレス開発が超捗った話
yu_yukk_y
1
350
Untangling Coroutine Testing (Droidcon Berlin 2022)
zsmb
1
480
Featured
See All Featured
Intergalactic Javascript Robots from Outer Space
tanoku
260
25k
Web Components: a chance to create the future
zenorocha
303
40k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
237
19k
What's in a price? How to price your products and services
michaelherold
229
9.4k
5 minutes of I Can Smell Your CMS
philhawksworth
196
18k
Building Flexible Design Systems
yeseniaperezcruz
310
34k
Navigating Team Friction
lara
175
11k
Ruby is Unlike a Banana
tanoku
91
9.3k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
316
19k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
107
16k
Fashionably flexible responsive web design (full day workshop)
malarkey
396
62k
The Straight Up "How To Draw Better" Workshop
denniskardys
225
130k
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