Your SlideShare is downloading. ×
0
Actor Model pattern for concurrency
Actor Model pattern for concurrency
Actor Model pattern for concurrency
Actor Model pattern for concurrency
Actor Model pattern for concurrency
Actor Model pattern for concurrency
Actor Model pattern for concurrency
Actor Model pattern for concurrency
Actor Model pattern for concurrency
Actor Model pattern for concurrency
Actor Model pattern for concurrency
Actor Model pattern for concurrency
Actor Model pattern for concurrency
Actor Model pattern for concurrency
Actor Model pattern for concurrency
Actor Model pattern for concurrency
Actor Model pattern for concurrency
Actor Model pattern for concurrency
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Actor Model pattern for concurrency

526

Published on

Actor model is a pattern to simplify writing efficient concurrent applications

Actor model is a pattern to simplify writing efficient concurrent applications

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
526
On Slideshare
0
From Embeds
0
Number of Embeds
14
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Actor Model
  • 2. Google thinks this is an Actor Model
  • 3. Actor model is a pattern to simplify writing efficient concurrent applications
  • 4. Concurrency: Writing applications where different parts could run in parallel
  • 5. Traditional approach to concurrency Multiple threads and Shared Objects
  • 6. void Session::onConnectionRequest(conn) { anvil.validateToken(conn.token); this.addConnection(conn); }
  • 7. void Session::onConnectionRequest(conn) { anvil.validateToken(conn.token); this.addConnection(conn); } void Session::onDisconnectionRequest(conn) { this.removeConnection(conn); }
  • 8. Publisher::onDisconnect() { scoped_lock lock; if (subscriber != NULL) { subscriber.setPublisher(NULL); } } Publisher::setSubscriber() { scoped_lock lock; subscriber = NULL; } Subscriber::onDisconnect() { scoped_lock lock; if (publisher != NULL) { publisher.setSubscriber(NULL); } } Subscriber::setPublisher() { scoped_lock lock; publisher = NULL; }
  • 9. Traditional concurrency It is difficult to build efficient applications while maintaining consistent state
  • 10. Fundamentally, the biggest challenge that SendGrid faces in development is concurrent programming. While what we do isn’t rocket science, doing it at a scale of over 500 million messages per day is extremely challenging (I’ve done rocket science, this is way harder).
  • 11. Solution 1: ad-hoc solutions and fix bugs forever
  • 12. Solution 2: rendition
  • 13. Solution 3: Actor Model
  • 14. Actor Model concurrency approach Asynchronous communication between objects Object state is only modified from one thread at a specific time
  • 15. Multiple threads and Shared Objects
  • 16. Actor Model
  • 17. Example sealed trait SessionMessage case object ConnectMessage extends SessionMessage case object DisconnectMessage extends SessionMessage class Session extends Actor with ActorLogging { def receive = { case ConnectMessage => log.info("Connecting") case DisconnectMessage => log.info("Disconnecting") } } object Demo extends App { val system = ActorSystem("MySystem") val session = system.actorOf(Props[Session], name="session1") session ! ConnectMessage session ! DisconnectMessage }
  • 18. Bonus Track supervision persistency distribution

×