Upload
celso-crivelaro
View
215
Download
0
Embed Size (px)
Citation preview
Actor Model in Ruby
Celso Crivelaro@celsocrivelaro
http://crivelaro.me1
DEVELOPER @
PROFESSOR @
My problem
Authorization
APIs
SMTP Protocol
Strange ProtocolStrange Lib
5
Strange Protocol / Strange Lib => Unmaintained
Bad documentation
Troubleshooting was impossible
Authorization
APIs
TCP/IP
Custom Protocol
SMTP Protocol
High Concurrency ~ 1000 connections
Fault Tolerant
Easy TCP Server API
Actors Reactor
10
Actor Model Theory
Actor 1Mailbox
Actor 2Mailbox
Actor 3Mailbox
Actors are similar to Objects
Send messages to each other
Asynchronous
Actors Objects
Synchronous
Create new ones
Isolated Share memory
Keep state
Actors can be distributed
15
Actor 1Mailbox
Actor 2Mailbox
Actor 3Mailbox
Fault Tolerant
Let it crash philosophy
Actor 1Mailbox
Actor 2Mailbox
Actor 3Mailbox
Actor 4Mailbox
A4 is linked to A2
A2 is warned when A4 crashes
A2 takes an action (restart A4)
Avoid defensive programming
Who implements Actors
20
Pykka
Celluloid ActorsRuby Objects
Same structure from classes
Runs over threads / fibers
Futures and Pools
Sync / Async Methods
25
When Actor crashes…
What if another actor could do
something?
Supervisors
30
Even if an Actor just terminates
ActorSupervisor
Restart Actor
Warn other Supervisor
Callbacks
Avoid begin… rescue... / if
Actions:
Must be finished to be CG’ed
35
Futures
Pool
Res 1 Res 2 Res 3
PoolRes 1
40
http://www.mikeperham.com/2015/10/14/should-you-use-celluloid/
Actors Reactor
Reactor Pattern
45
Handler 1
Handler 2
Dispatcher Handler 3
Handles service request
Delivered concurrently to handlers
Demultiplexing
Event
Event
Event
https://github.com/celluloid/nio4r
Server Celluloid:IOSupervisor
50
Important
Mutant Data Structure
Actor 1Mailbox
Actor 2Mailbox
Actor 3Mailbox
Microservices
55
Evaluate the best concurrency model
Celluloid Documentation
References
http://www.brianstorti.com/the-actor-model/
https://www.sitepoint.com/an-introduction-to-celluloid-part-i/
https://github.com/celluloid/celluloid-io
http://queroserdevlocaweb.com.br/
Thank you!
@celsocrivelaroSlides at http://crivelaro.me