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
430
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.4k
Elixir and Ecto
vanstee
5
750
Bootstrap
vanstee
8
680
HTTP API Design for iOS Applications
vanstee
11
510
Consensus: An Introduction to Raft
vanstee
22
2.7k
Convergent Replicated Data Types
vanstee
4
630
Pour Over Brewing Method
vanstee
1
260
Map Reduce & Ruby
vanstee
10
640
Other Decks in Programming
See All in Programming
My favorite script, "dsl.rb"
yui_knk
2
580
Project Loom 概要と Scala における有用性 @ ScalaMatsuri2024
th0rikosh1
0
290
Railsでクリーンアーキテクチャを考えてきた
suzukimar
2
320
GoのWasmでWebRTC P2Pで通信する
ponyo877
0
270
RustのReturn-position impl trait in trait (RPITIT) の実装を雑に見てみる
tako8ki
1
140
Ruby Function Composition
bkuhlmann
1
380
Androidアプリのテスト駆動開発入門
tonionagauzzi
0
120
앱 성능 영혼까지 끌어올리기
veronikapj
0
610
Ruby と Rails の小ネタ集
daisukeshinoku
2
150
ぎゃるえんじにあがハッカソンの虜になった!
rino7_tech
1
200
TypeScriptを活用したi18n対応
minako__ph
8
1.5k
ソートできるUUID v7をJavaで使うときの話
yoshiori
7
4.6k
Featured
See All Featured
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
27
2.4k
In The Pink: A Labor of Love
frogandcode
138
21k
Building a Scalable Design System with Sketch
lauravandoore
457
32k
Reflections from 52 weeks, 52 projects
jeffersonlam
345
19k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
155
14k
Faster Mobile Websites
deanohume
300
30k
From Idea to $5000 a Month in 5 Months
shpigford
377
46k
Infographics Made Easy
chrislema
238
18k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
34
6.2k
The Art of Programming - Codeland 2020
erikaheidi
46
12k
What’s in a name? Adding method to the madness
productmarketing
PRO
18
2.8k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
24
1.7k
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