Actor Model pattern for concurrency
Upcoming SlideShare
Loading in...5
×
 

Actor Model pattern for concurrency

on

  • 357 views

Actor model is a pattern to simplify writing efficient concurrent applications

Actor model is a pattern to simplify writing efficient concurrent applications

Statistics

Views

Total Views
357
Views on SlideShare
309
Embed Views
48

Actions

Likes
0
Downloads
2
Comments
0

8 Embeds 48

http://kalimotxocoding.blogspot.in 19
http://kalimotxocoding.blogspot.com 17
http://kalimotxocoding.blogspot.com.es 5
http://kalimotxocoding.blogspot.ro 2
http://kalimotxocoding.blogspot.fr 2
http://plus.url.google.com 1
http://kalimotxocoding.blogspot.tw 1
http://kalimotxocoding.blogspot.fi 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Actor Model pattern for concurrency Actor Model pattern for concurrency Presentation Transcript

  • Actor Model
  • Google thinks this is an Actor Model
  • Actor model is a pattern to simplify writing efficient concurrent applications
  • Concurrency: Writing applications where different parts could run in parallel
  • Traditional approach to concurrency Multiple threads and Shared Objects
  • void Session::onConnectionRequest(conn) { anvil.validateToken(conn.token); this.addConnection(conn); }
  • void Session::onConnectionRequest(conn) { anvil.validateToken(conn.token); this.addConnection(conn); } void Session::onDisconnectionRequest(conn) { this.removeConnection(conn); }
  • 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; }
  • Traditional concurrency It is difficult to build efficient applications while maintaining consistent state
  • 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).
  • Solution 1: ad-hoc solutions and fix bugs forever
  • Solution 2: rendition
  • Solution 3: Actor Model
  • Actor Model concurrency approach Asynchronous communication between objects Object state is only modified from one thread at a specific time
  • Multiple threads and Shared Objects
  • Actor Model
  • 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 }
  • Bonus Track supervision persistency distribution