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
730
Bootstrap
vanstee
8
670
HTTP API Design for iOS Applications
vanstee
11
500
Consensus: An Introduction to Raft
vanstee
22
2.6k
Convergent Replicated Data Types
vanstee
4
600
Pour Over Brewing Method
vanstee
1
250
Map Reduce & Ruby
vanstee
10
620
Other Decks in Programming
See All in Programming
Hanami and htmx
bkuhlmann
0
220
Ruby GitHub Packages
bkuhlmann
0
640
Komplexe Oberflächen mit SVG und der Web Animation API
joergneumann
0
680
PHP8.3の機能を振り返る / Review of PHP 8.3 features
seike460
PRO
1
120
CDKコントリビュートの最初の壁を越えよう! -簡単issueの見つけ方-
badmintoncryer
3
200
サイコロで理解する統計的仮説検定の考え方
tatamiya
4
1k
Compose-View Interop in Practice (mDevCamp 2024)
stewemetal
0
160
Let's learn code review
riofujimon
2
570
TCAとKMPを用いた新規動画配信アプリ 「ABEMA Live」の設計
tomu28
2
130
Exploring the Implementation of “t.Run”, “t.Parallel”, and “t.Cleanup”
akarin
1
110
大規模UIKitベースアプリへのTCAの段階的導入/gradual-adoption-of-tca-in-a-large-scale-uikit-based-app
takehilo
2
200
Next.js App Router
quramy
11
1.6k
Featured
See All Featured
Dealing with People You Can't Stand - Big Design 2015
cassininazir
358
22k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
20
1.6k
Infographics Made Easy
chrislema
238
18k
Building Effective Engineering Teams - LeadDev
addyosmani
32
1.9k
[RailsConf 2023] Rails as a piece of cake
palkan
28
4k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
22
1.6k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
242
1.2M
The MySQL Ecosystem @ GitHub 2015
samlambert
244
12k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
20
1.7k
Six Lessons from altMBA
skipperchong
22
3k
Being A Developer After 40
akosma
66
580k
Unsuck your backbone
ammeep
663
57k
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