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
A Crash Course on Celluloid (GoGaRuCo 2012)
Search
tarcieri
September 15, 2012
Programming
6
550
A Crash Course on Celluloid (GoGaRuCo 2012)
A quick introduction to the basic features of Celluloid
tarcieri
September 15, 2012
Tweet
Share
More Decks by tarcieri
See All by tarcieri
Embedded cryptography in Rust: RustCrypto + Veriform
tarcieri
0
970
Rhapsody in Zero Knowledge - Proving without Revealing
tarcieri
2
290
Rust in Blockchain - Tendermint KMS and Abscissa
tarcieri
0
560
Insane in the Blockchain
tarcieri
1
700
Macaroons for Rust
tarcieri
3
790
A Protocol for Interledger Payments
tarcieri
0
380
Frontiers in Cryptography
tarcieri
2
1.6k
Macaroons - A Better Kind of Cookie
tarcieri
1
290
Thoughts on Rust Cryptography
tarcieri
6
6.6k
Other Decks in Programming
See All in Programming
Pinia Colada が実現するスマートな非同期処理
naokihaba
4
230
アジャイルを支えるテストアーキテクチャ設計/Test Architecting for Agile
goyoki
9
3.3k
型付き API リクエストを実現するいくつかの手法とその選択 / Typed API Request
euxn23
8
2.2k
リアーキテクチャxDDD 1年間の取り組みと進化
hsawaji
1
220
ペアーズにおけるAmazon Bedrockを⽤いた障害対応⽀援 ⽣成AIツールの導⼊事例 @ 20241115配信AWSウェビナー登壇
fukubaka0825
6
2k
役立つログに取り組もう
irof
28
9.6k
AI時代におけるSRE、 あるいはエンジニアの生存戦略
pyama86
6
1.2k
Creating a Free Video Ad Network on the Edge
mizoguchicoji
0
120
Amazon Bedrock Agentsを用いてアプリ開発してみた!
har1101
0
340
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
190
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
120
ふかぼれ!CSSセレクターモジュール / Fukabore! CSS Selectors Module
petamoriken
0
150
Featured
See All Featured
Facilitating Awesome Meetings
lara
50
6.1k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
329
21k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
16
2.1k
Docker and Python
trallard
40
3.1k
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
Fireside Chat
paigeccino
34
3k
Agile that works and the tools we love
rasmusluckow
327
21k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
Navigating Team Friction
lara
183
14k
Site-Speed That Sticks
csswizardry
0
27
Raft: Consensus for Rubyists
vanstee
136
6.6k
Transcript
A Crash Course on Tony Arcieri GoGaRuCo September 15th, 2012
Saturday, September 15, 12
Saturday, September 15, 12
We’re hiring! Saturday, September 15, 12
“Threads on Rails!” Saturday, September 15, 12
Sidekiq What if 1 Sidekiq process could do the work
of 20 Resque processes? http://mperham.github.com/sidekiq/ Saturday, September 15, 12
OOP + Actor Model Saturday, September 15, 12
“I thought of objects being like biological cells and/or individual
computers on a network, only able to communicate with messages” - Alan Kay, creator of Smalltalk, on the meaning of "object oriented programming" Saturday, September 15, 12
Active Objects Based on the Actor Model Saturday, September 15,
12
Saturday, September 15, 12
Saturday, September 15, 12
Actor Model •Actors are computational entities that can receive messages
•Each actor has a unique address •If you know an actor’s address, you can send it messages •Actors can create new actors Saturday, September 15, 12
I’m not the first to do Actor Model + OOP
Saturday, September 15, 12
Saturday, September 15, 12
Forgotten approach to concurrency? Saturday, September 15, 12
Example Saturday, September 15, 12
require 'celluloid' class Launcher include Celluloid def launch 3.downto(1) do
|count| puts "#{count}..." sleep 1 end puts "BLASTOFF!" end end Saturday, September 15, 12
require 'celluloid' class Launcher include Celluloid def launch 3.downto(1) do
|count| puts "#{count}..." sleep 1 end puts "BLASTOFF!" end end Saturday, September 15, 12
>> launcher = Launcher.new => #<Celluloid::Actor(Launcher:0x3fe8bef4d544)> Saturday, September 15, 12
Synchronous Calls Saturday, September 15, 12
>> launcher = Launcher.new => #<Celluloid::Actor(Launcher:0x3fe8bef4d544)> >> launcher.launch Saturday, September
15, 12
>> launcher = Launcher.new => #<Celluloid::Actor(Launcher:0x3fe8bef4d544)> >> launcher.launch 3... Saturday,
September 15, 12
>> launcher = Launcher.new => #<Celluloid::Actor(Launcher:0x3fe8bef4d544)> >> launcher.launch 3... 2...
Saturday, September 15, 12
>> launcher = Launcher.new => #<Celluloid::Actor(Launcher:0x3fe8bef4d544)> >> launcher.launch 3... 2...
1... Saturday, September 15, 12
>> launcher = Launcher.new => #<Celluloid::Actor(Launcher:0x3fe8bef4d544)> >> launcher.launch 3... 2...
1... BLASTOFF! => nil >> Saturday, September 15, 12
&DOOHU &HOOXORLG $FWRU3UR[\ &$// 5HFHLYHU &HOOXORLG 0DLOER[ 5(63216( &HOOXORLG 0DLOER[
&HOOXORLG$FWRU &HOOXORLG&DOO &HOOXORLG5HVSRQVH Synchronous Calls Saturday, September 15, 12
Asynchronous Calls Saturday, September 15, 12
>> launcher = Launcher.new => #<Celluloid::Actor(Launcher:0x3fe8bef4d544)> >> launcher.async.launch Saturday, September
15, 12
>> launcher = Launcher.new => #<Celluloid::Actor(Launcher:0x3fe8bef4d544)> >> launcher.async.launch New syntax!
Saturday, September 15, 12
THEY TOOK ‘ER BANG METHERDS!!!!! Saturday, September 15, 12
You’ll get them back in Celluloid 1.0 Saturday, September 15,
12
>> launcher = Launcher.new => #<Celluloid::Actor(Launcher:0x3fe8bef4d544)> >> launcher.async.launch Saturday, September
15, 12
>> launcher = Launcher.new => #<Celluloid::Actor(Launcher:0x3fe8bef4d544)> >> launcher.async.launch => nil
>> Returns immediately Saturday, September 15, 12
>> launcher = Launcher.new => #<Celluloid::Actor(Launcher:0x3fe8bef4d544)> >> launcher.async.launch => nil
>> 3... Saturday, September 15, 12
>> launcher = Launcher.new => #<Celluloid::Actor(Launcher:0x3fe8bef4d544)> >> launcher.async.launch => nil
>> 3... 2... Saturday, September 15, 12
>> launcher = Launcher.new => #<Celluloid::Actor(Launcher:0x3fe8bef4d544)> >> launcher.async.launch => nil
>> 3... 2... 1... Saturday, September 15, 12
>> launcher = Launcher.new => #<Celluloid::Actor(Launcher:0x3fe8bef4d544)> >> launcher.async.launch => nil
>> 3... 2... 1... BLASTOFF! Saturday, September 15, 12
Asynchronous Calls &DOOHU &HOOXORLG $V\QF3UR[\ &$// 5HFHLYHU &HOOXORLG 0DLOER[ &HOOXORLG$FWRU
&HOOXORLG&DOO Saturday, September 15, 12
Futures Saturday, September 15, 12
class FibonacciWorker include Celluloid def fib(n) n < 2 ?
n : fib(n-1) + fib(n-2) end end Saturday, September 15, 12
>> worker = FibonacciWorker.new => #<Celluloid::Actor(FibonacciWorker:0x3ffdcaed65cc)> >> future = worker.future.fib(40)
=> #<Celluloid::Future:0x007ffb9201f0a0> Saturday, September 15, 12
>> worker = FibonacciWorker.new => #<Celluloid::Actor(FibonacciWorker:0x3ffdcaed65cc)> >> future = worker.future.fib(40)
=> #<Celluloid::Future:0x007ffb9201f0a0> Returns immediately Saturday, September 15, 12
>> worker = FibonacciWorker.new => #<Celluloid::Actor(FibonacciWorker:0x3ffdcaed65cc)> >> future = worker.future.fib(40)
=> #<Celluloid::Future:0x007ffb9201f0a0> >> future.value Saturday, September 15, 12
>> worker = FibonacciWorker.new => #<Celluloid::Actor(FibonacciWorker:0x3ffdcaed65cc)> >> future = worker.future.fib(40)
=> #<Celluloid::Future:0x007ffb9201f0a0> >> future.value Blocks until complete Saturday, September 15, 12
>> worker = FibonacciWorker.new => #<Celluloid::Actor(FibonacciWorker:0x3ffdcaed65cc)> >> future = worker.future.fib(40)
=> #<Celluloid::Future:0x007ffb9201f0a0> >> future.value => 102334155 Saturday, September 15, 12
&DOOHU &HOOXORLG $FWRU3UR[\ 5HFHLYHU &HOOXORLG 0DLOER[ &HOOXORLG$FWRU &HOOXORLG&DOO &$// &HOOXORLG
0DLOER[ )8785( &HOOXORLG )XWXUH &HOOXORLG5HVSRQVH 9$/8(" 9$/8( Futures Saturday, September 15, 12
Pools Saturday, September 15, 12
>> pool = FibonacciWorker.pool(size: 16) => #<Celluloid::Pool(FibonacciWorker:0x3ffdcaed65cc)> Saturday, September 15,
12
>> pool = FibonacciWorker.pool => #<Celluloid::Pool(FibonacciWorker:0x3ffdcaed65cc)> 1 actor per CPU
(by default) Saturday, September 15, 12
>> pool = FibonacciWorker.pool => #<Celluloid::Pool(FibonacciWorker:0x3ffdcaed65cc)> >> (32...40).map { |n|
pool.future.fib(n) }.map(&:value) Saturday, September 15, 12
>> pool = FibonacciWorker.pool => #<Celluloid::Pool(FibonacciWorker:0x3ffdcaed65cc)> >> (32...40).map { |n|
pool.future.fib(n) }.map(&:value) => [2178309, 3524578, 5702887, 9227465, 14930352, 24157817, 39088169, 63245986] Saturday, September 15, 12
Beware the GIL •YARV can do parallel I/O in threads
•...but NOT parallel computation (e.g. fib) •JRuby and Rubinius will light up all your cores :) Saturday, September 15, 12
Twitter: @bascule @celluloidrb Celluloid: celluloid.io Blog: unlimitednovelty.com Saturday, September 15,
12