actor model in ruby
TRANSCRIPT
![Page 1: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/1.jpg)
Actor Model in Ruby
Celso Crivelaro@celsocrivelaro
http://crivelaro.me1
![Page 2: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/2.jpg)
DEVELOPER @
PROFESSOR @
![Page 3: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/3.jpg)
![Page 4: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/4.jpg)
My problem
![Page 5: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/5.jpg)
Authorization
APIs
SMTP Protocol
Strange ProtocolStrange Lib
5
![Page 6: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/6.jpg)
Strange Protocol / Strange Lib => Unmaintained
Bad documentation
Troubleshooting was impossible
![Page 7: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/7.jpg)
Authorization
APIs
TCP/IP
Custom Protocol
SMTP Protocol
![Page 8: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/8.jpg)
High Concurrency ~ 1000 connections
Fault Tolerant
Easy TCP Server API
![Page 9: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/9.jpg)
![Page 10: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/10.jpg)
Actors Reactor
10
![Page 11: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/11.jpg)
Actor Model Theory
![Page 12: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/12.jpg)
Actor 1Mailbox
Actor 2Mailbox
Actor 3Mailbox
![Page 13: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/13.jpg)
Actors are similar to Objects
![Page 14: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/14.jpg)
Send messages to each other
Asynchronous
Actors Objects
Synchronous
Create new ones
Isolated Share memory
Keep state
![Page 15: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/15.jpg)
Actors can be distributed
15
![Page 16: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/16.jpg)
Actor 1Mailbox
Actor 2Mailbox
Actor 3Mailbox
![Page 17: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/17.jpg)
Fault Tolerant
![Page 18: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/18.jpg)
Let it crash philosophy
![Page 19: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/19.jpg)
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
![Page 20: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/20.jpg)
Who implements Actors
20
![Page 21: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/21.jpg)
Pykka
![Page 22: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/22.jpg)
![Page 23: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/23.jpg)
Celluloid ActorsRuby Objects
Same structure from classes
Runs over threads / fibers
Futures and Pools
Sync / Async Methods
![Page 24: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/24.jpg)
![Page 25: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/25.jpg)
25
![Page 26: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/26.jpg)
When Actor crashes…
![Page 27: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/27.jpg)
![Page 28: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/28.jpg)
What if another actor could do
something?
![Page 29: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/29.jpg)
Supervisors
![Page 30: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/30.jpg)
30
![Page 31: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/31.jpg)
![Page 32: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/32.jpg)
Even if an Actor just terminates
![Page 33: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/33.jpg)
![Page 34: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/34.jpg)
ActorSupervisor
Restart Actor
Warn other Supervisor
Callbacks
Avoid begin… rescue... / if
Actions:
![Page 35: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/35.jpg)
Must be finished to be CG’ed
35
![Page 36: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/36.jpg)
![Page 37: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/37.jpg)
Futures
![Page 38: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/38.jpg)
![Page 39: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/39.jpg)
Pool
![Page 40: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/40.jpg)
Res 1 Res 2 Res 3
PoolRes 1
40
![Page 41: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/41.jpg)
![Page 42: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/42.jpg)
http://www.mikeperham.com/2015/10/14/should-you-use-celluloid/
![Page 43: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/43.jpg)
![Page 44: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/44.jpg)
Actors Reactor
![Page 45: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/45.jpg)
Reactor Pattern
45
![Page 46: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/46.jpg)
Handler 1
Handler 2
Dispatcher Handler 3
Handles service request
Delivered concurrently to handlers
Demultiplexing
Event
Event
Event
![Page 47: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/47.jpg)
https://github.com/celluloid/nio4r
![Page 48: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/48.jpg)
![Page 49: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/49.jpg)
![Page 50: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/50.jpg)
Server Celluloid:IOSupervisor
50
![Page 51: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/51.jpg)
![Page 52: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/52.jpg)
![Page 53: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/53.jpg)
Important
![Page 54: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/54.jpg)
Mutant Data Structure
![Page 55: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/55.jpg)
Actor 1Mailbox
Actor 2Mailbox
Actor 3Mailbox
Microservices
55
![Page 56: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/56.jpg)
Evaluate the best concurrency model
Celluloid Documentation
![Page 57: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/57.jpg)
References
![Page 58: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/58.jpg)
http://www.brianstorti.com/the-actor-model/
![Page 59: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/59.jpg)
![Page 60: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/60.jpg)
https://www.sitepoint.com/an-introduction-to-celluloid-part-i/
![Page 61: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/61.jpg)
https://github.com/celluloid/celluloid-io
![Page 62: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/62.jpg)
http://queroserdevlocaweb.com.br/
![Page 63: Actor model in Ruby](https://reader031.vdocuments.site/reader031/viewer/2022020301/58ef11ff1a28ab9d408b45a1/html5/thumbnails/63.jpg)
Thank you!
@celsocrivelaroSlides at http://crivelaro.me