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
440
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
134
6.5k
Elixir and Ecto
vanstee
5
780
Bootstrap
vanstee
8
690
HTTP API Design for iOS Applications
vanstee
11
520
Consensus: An Introduction to Raft
vanstee
22
2.7k
Convergent Replicated Data Types
vanstee
4
640
Pour Over Brewing Method
vanstee
1
270
Map Reduce & Ruby
vanstee
10
660
Other Decks in Programming
See All in Programming
DynamoDB コスト最適化っぽいことの基本 with Terraform
kuro_kurorrr
2
250
君たちはどうコードをレビューする (される) か / 大吉祥寺.pm
utgwkk
15
8.5k
Rust.Nagoya #1
codemountains
0
170
Rustのweb開発を助ける 便利なツール紹介
yuki0418
1
190
なぜ宣言的 UI は壊れにくいのか / Why declarative UI is less fragile
uenitty
29
13k
Android開発者のための Kotlin Multiplatform入門
ntaro
0
190
Introduction of Happy Eyeballs Version 2 (RFC8305) to the Socket library
coe401_
1
220
CSC307 Lecture 11
javiergs
PRO
0
240
From Spring Boot 2 to Spring Boot 3 with Java 22 and Jakarta EE
ivargrimstad
0
1.9k
はしめてのプログラミングとロボット制御
watawatavoltage
0
290
TiDB Serverless ~理想のServerless DBを考える~
soso_15315
1
160
Introduction to GitOps
hwchiu
0
110
Featured
See All Featured
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
26
1.8k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
360
22k
What’s in a name? Adding method to the madness
productmarketing
PRO
21
2.9k
Code Review Best Practice
trishagee
58
16k
Rails Girls Zürich Keynote
gr2m
93
13k
Why Our Code Smells
bkeepers
PRO
332
56k
Designing Experiences People Love
moore
136
23k
From Idea to $5000 a Month in 5 Months
shpigford
377
46k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
662
120k
Optimising Largest Contentful Paint
csswizardry
18
2.6k
How To Stay Up To Date on Web Technology
chriscoyier
784
250k
Building a Scalable Design System with Sketch
lauravandoore
458
32k
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