actors evolved- rotem hermon

46
Rotem Hermon @margolis20 Actors, Evolved #dmconf15

Upload: distributed-matters

Post on 08-Jan-2017

678 views

Category:

Data & Analytics


1 download

TRANSCRIPT

Page 1: Actors evolved- Rotem Hermon

Rotem Hermon@margolis20

Actors, Evolved#dmconf15

Page 2: Actors evolved- Rotem Hermon

Not THAT kind of actors.

Page 3: Actors evolved- Rotem Hermon

Multithreading

Page 4: Actors evolved- Rotem Hermon

The problem with multi-threaded concurrency

• Shared memory and state

• Race conditions

• Locks and deadlocks

• Blocking calls

• Hard to understand and maintain

• Not easily distributed

Page 5: Actors evolved- Rotem Hermon

Threads are EVIL!

Page 6: Actors evolved- Rotem Hermon

There has to be a better way…

Page 7: Actors evolved- Rotem Hermon

The Actor Model

• Formalized in 1973 (Carl Hewitt)

• Concurrency by Message Passing

• Avoids problems of threading and locking

Page 8: Actors evolved- Rotem Hermon

An Actor, Carl Hewitt definition

• The fundamental unit of computation that embodies:

• Processing

• Storage

• Communication

• An actor can:

• Create new Actors

• Send messages to Actors

• Designate how to handle the next message

Page 9: Actors evolved- Rotem Hermon

An Actor

• Lightweight

• Never shares state

• Communicates through asynchronous messages

• Mailbox buffers incoming messages

• Processes one message at a time

Page 10: Actors evolved- Rotem Hermon

An Actor

• Lightweight

• Never shares state

• Communicates through asynchronous messages

• Mailbox buffers incoming messages

• Processes one message at a time

• Single threaded

Page 11: Actors evolved- Rotem Hermon

The Actor Model

• Higher abstraction level

• Simpler concurrent programming model

• Write single-threaded code (easier to understand)

• Concurrency and scale via actor instances

• Maximizes CPU utilization

• Easy to distribute

Page 12: Actors evolved- Rotem Hermon

(Actors are actually Nanoservices)

Page 13: Actors evolved- Rotem Hermon

Leading Classic Actor Implementations

• Erlang

• Developed in the late 90s by Ericsson for HA telecom exchanges

• Actors are a core language feature

• Akka

• A JVM (Scala/Java) Actor framework library

• Started by Jonas Bonér in 2009

• Became part of Typesafe (company behind Scala)

• .NET port in progress since 2014 (Akka.NET)

Page 14: Actors evolved- Rotem Hermon

Akka Fundamentals

Actors Contains:

• State

• Behavior

• An actor can “switch” its internal behavior

• Mailbox

• Several types of mailboxes

• Children

• An actor is “responsible” for other actors it creates - Supervisor

Page 15: Actors evolved- Rotem Hermon

Akka Fundamentals

• Actors form an hierarchical structure

Page 16: Actors evolved- Rotem Hermon

Akka Fundamentals

• Actor Lifecycle

• Actors needs to be created and destroyed

• Fault handling is done via supervision hierarchies

• Several available supervision strategies

Page 17: Actors evolved- Rotem Hermon

Akka Fundamentals

• Location Transparency

• Actors can be created remotely

• Actors are called via an actor reference, same for local and remote

• Akka Clustering for additional features

Page 18: Actors evolved- Rotem Hermon

Akka Fundamentals

• Dispatchers

• Schedules the message delivery to actors (code execution)

• Can be shared across actors

• Several types of dispatchers and configurations

Page 19: Actors evolved- Rotem Hermon

Akka Fundamentals

• Routers

• An actor that routes messages to other actors

• Several routing strategies

Page 20: Actors evolved- Rotem Hermon
Page 21: Actors evolved- Rotem Hermon

There has to be a better way…

Page 22: Actors evolved- Rotem Hermon

Virtual Actors

• A simplified Actors implementation with a higher abstraction level

• Introduced by Microsoft Research – Project Orleans

• Goals:

• Make distributed application programming easier

• Prefer developer productivity and transparent scalability

• “A programming model and runtime for building cloud native

services”

Page 23: Actors evolved- Rotem Hermon

Virtual Actors

• A Virtual Actor:

always existsand

never fails

Page 24: Actors evolved- Rotem Hermon

Virtual Actors

Actor types:

• Worker

• An auto-scaling processing unit – multiple instances created by framework as needed

Page 25: Actors evolved- Rotem Hermon

Virtual Actors

Actor types:

• Single Activation

• Guaranteed to have a single active instance in the cluster

Page 26: Actors evolved- Rotem Hermon

Virtual Actors

Actor types:

• Single Activation

• Guaranteed to have a single active instance in the cluster

• A Stateful application middle-tier!

Page 27: Actors evolved- Rotem Hermon

Virtual Actor Framework

• A runtime providing virtual “actor space”, analogues to virtual memory

• Handles Actor placement, activation and GC when needed

• Balances resources across the cluster, provides elastic scalability

Page 28: Actors evolved- Rotem Hermon

Virtual Actor Framework

Node

Node

Node

Node

Node

Node

Page 29: Actors evolved- Rotem Hermon

Virtual Actor Framework

Page 30: Actors evolved- Rotem Hermon

Virtual Actor Framework

User#21

User#73

Game#254 Game

#33

Page 31: Actors evolved- Rotem Hermon

Virtual Actor Framework

Auto Scaling

Page 32: Actors evolved- Rotem Hermon

Virtual Actor Framework

Auto Scaling

Page 33: Actors evolved- Rotem Hermon

Virtual Actor Framework

Auto Scaling

Page 34: Actors evolved- Rotem Hermon

Virtual Actor Framework

Auto Scaling

Page 35: Actors evolved- Rotem Hermon

Virtual Actor Framework

Failure Recovery

Page 36: Actors evolved- Rotem Hermon

Virtual Actor Framework

Failure Recovery

Page 37: Actors evolved- Rotem Hermon

Virtual Actor Framework

Failure Recovery

Page 38: Actors evolved- Rotem Hermon

Simplified Programming Model

• An Actor is a class, implementing an interface with asynchronous methods

• The caller of an Actor uses the actor interface via a proxy

• Messaging is transparent and handled by the runtime. Programmers deal with interfaces and methods

Page 39: Actors evolved- Rotem Hermon

Simplified Programming Model

Page 40: Actors evolved- Rotem Hermon

Simplified Programming Model

Page 41: Actors evolved- Rotem Hermon

Use Cases

• Stateful Services

• Smart Cache

• Modeling objects at scale (games, IoT)

• Protecting resources / Aggregations

Page 42: Actors evolved- Rotem Hermon

Virtual Actor Implementations

• Orleans (.NET)

• Started by Microsoft Research in 2011, in production since 2012

• Service high scale services on Azure (Halo 4 cloud services)

• Open sourced in January 2015, active community

• Orbit (Java)

• Developed by BioWare (division of Electronic Arts)

• Inspired by Orleans (“not a port but a re-write”)

• Powering online game services

• Azure Service Fabric (Reliable Actors)

Page 43: Actors evolved- Rotem Hermon
Page 44: Actors evolved- Rotem Hermon

Virtual Actors (Orleans)

• Focus on simplicity and productivity

• Implicit lifecycle, handled by runtime

• Automatic clustering and load balancing

• No hierarchy, all actors are directly accessible

• Actor interfaces are regular interfaces (standard OOP)

Classic Actors (Akka)

• Provide full power (exposing complexity)

• Explicit lifecycle, handled by programmer

• Clustering and load balancing available (but more complex)

• Actors are hierarchical and accessible by path

• Actors communicates via explicit message classes

Page 45: Actors evolved- Rotem Hermon

Virtual Actors (Orleans)

Choose if:

• Need a simple model for distributed applications

• Automatic and straightforward scaling

• Development team with variedlevels of experience

Classic Actors (Akka)

Choose if:

• Need full power – complex topologies, fine grain failure handling, dynamic changing of behavior, explicit message handling

• Experienced development team

Page 46: Actors evolved- Rotem Hermon

Thank You!

Rotem Hermon@margolis20

VP Architecture @ Gigya