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.8k
Elixir and Ecto
vanstee
5
880
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
750
Other Decks in Programming
See All in Programming
『品質』という言葉が嫌いな理由
korimu
0
140
CloudNativePGがCNCF Sandboxプロジェクトになったぞ! 〜CloudNativePGの仕組みの紹介〜
nnaka2992
0
210
『改訂新版 良いコード/悪いコードで学ぶ設計入門』活用方法−爆速でスキルアップする!効果的な学習アプローチ / effective-learning-of-good-code
minodriven
29
5.1k
Terraform で作る Amazon ECS の CI/CD パイプライン
hiyanger
0
140
『GO』アプリ バックエンドサーバのコスト削減
mot_techtalk
0
100
[JAWS-UG横浜 #79] re:Invent 2024 の DB アップデートは Multi-Region!
maroon1st
1
140
AWS Organizations で実現する、 マルチ AWS アカウントのルートユーザー管理からの脱却
atpons
0
120
Lottieアニメーションをカスタマイズしてみた
tahia910
0
100
Swiftコンパイラ超入門+async関数の仕組み
shiz
0
210
自分ひとりから始められる生産性向上の取り組み #でぃーぷらすオオサカ
irof
8
2.3k
定理証明プラットフォーム lapisla.net
abap34
1
1.7k
昭和の職場からアジャイルの世界へ
kumagoro95
1
320
Featured
See All Featured
Code Reviewing Like a Champion
maltzj
521
39k
How GitHub (no longer) Works
holman
313
140k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
29
2.2k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7.1k
Designing Experiences People Love
moore
139
23k
Fashionably flexible responsive web design (full day workshop)
malarkey
406
66k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
6
530
The World Runs on Bad Software
bkeepers
PRO
67
11k
Designing for Performance
lara
604
68k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3k
A Tale of Four Properties
chriscoyier
158
23k
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