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
630
Other Decks in Programming
See All in Programming
戦略的DDDは重いのか? / Is strategic DDD heavy?
pictiny
3
1.6k
初心者のためのRubyKaigi入門/RubyKaigi Introduction
a_matsuda
10
1.8k
Revisiting the Hotwire Landscape after Turbo 8 @ RailsConf 2024, Detroit
marcoroth
3
570
TypeScriptのパフォーマンス改善
yajihum
11
4.6k
酒飲んでたらテックリードになった話
spbaya0141
0
190
Anthropic Cookbook のおすすめレシピ
schroneko
7
1.5k
Implementing Design Systems in Swift
seyfoyun
2
520
Three ways to use AI on Android: The Good, the Bad and the Ugly
marxallski
0
120
Direct Style Effect Systems The Print[A] ExampleA Comprehension Aid
philipschwarz
PRO
0
390
Webアプリをできるだけコードを手書きしないで作ってみる
tomokusaba
2
230
AmperとFleetを使ったAndroidアプリ
yoppie
0
290
Powerfully Typed TypeScript
euxn23
3
790
Featured
See All Featured
Building Effective Engineering Teams - LeadDev
addyosmani
33
1.9k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
34
8.9k
Building an army of robots
kneath
300
41k
Making Projects Easy
brettharned
109
5.5k
Build The Right Thing And Hit Your Dates
maggiecrowley
25
2k
Large-scale JavaScript Application Architecture
addyosmani
504
110k
jQuery: Nuts, Bolts and Bling
dougneiner
60
7.2k
Git: the NoSQL Database
bkeepers
PRO
423
63k
Learning to Love Humans: Emotional Interface Design
aarron
267
39k
What’s in a name? Adding method to the madness
productmarketing
PRO
17
2.7k
Reflections from 52 weeks, 52 projects
jeffersonlam
345
19k
Web Components: a chance to create the future
zenorocha
306
41k
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