19
Web-scale Architecture NL Introduction to akka.net Edwin van Wijk [email protected] @evanwijk

Web-scale Architecture NL · Actors •Akka.NET is based on the Actor Model paradigm •All work in an actor model system is executed by Actors •An Actor is a single threaded entity

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Web-scale Architecture NL · Actors •Akka.NET is based on the Actor Model paradigm •All work in an actor model system is executed by Actors •An Actor is a single threaded entity

Web-scale Architecture NL

Introduction to akka.net

Edwin van [email protected]

@evanwijk

Page 2: Web-scale Architecture NL · Actors •Akka.NET is based on the Actor Model paradigm •All work in an actor model system is executed by Actors •An Actor is a single threaded entity

What is Akka.NET?

• Akka.NET is a framework and runtime for building highly concurrent, distributed, and fault tolerant event-driven applications on .NET & Mono

• Community driven .NET port of the Java/Scala Akka framework

• Open Source (Apache 2 License)

• 1.0 version released (stable API)

• Commercial training, consulting & support available from

Page 3: Web-scale Architecture NL · Actors •Akka.NET is based on the Actor Model paradigm •All work in an actor model system is executed by Actors •An Actor is a single threaded entity

Actors

• Akka.NET is based on the Actor Model paradigm

• All work in an actor model system is executed by Actors

• An Actor is a single threaded entity that acts upon received messages• Event driven (non-blocking async messaging using a “mailbox”)• Akka.NET takes care of threading (state is private)• Lightweight (millions of actors per GB of heap memory)• Location transparency

Page 4: Web-scale Architecture NL · Actors •Akka.NET is based on the Actor Model paradigm •All work in an actor model system is executed by Actors •An Actor is a single threaded entity

Configuration

• Actors are configured using HOCON• Human Optimized Configuration Object Notation

• JSON like structure

• Can be specified in code (parsed from a string) or in the .config file in a CDATA block

Page 5: Web-scale Architecture NL · Actors •Akka.NET is based on the Actor Model paradigm •All work in an actor model system is executed by Actors •An Actor is a single threaded entity

Actor hierarchy

• All actors live within an ActorSystem• A process can host multiple actorsystems

• Within the ActorSystem the actors form a hierarchical structure• Supervision• Fault tolerance

• Each actor is addressable using an ActorPath:• Local: /user/a1/b1/c2• Remote: akka.tcp://my-system@localhost:9999/user/a2/b3

ActorSystem Address PathProtocol

Page 6: Web-scale Architecture NL · Actors •Akka.NET is based on the Actor Model paradigm •All work in an actor model system is executed by Actors •An Actor is a single threaded entity

Supervision

• Each parent actor supervises his childactors• Isolate failure

• The configured SuperVision Strategydictates how an actor deals with a failure in a child actor• OneForOne - only the failed child is impacted• AllForOne - all children are impacted

• Based on the exception type, a certain action is taken:• Resume, Restart, Stop, Escalate

Page 7: Web-scale Architecture NL · Actors •Akka.NET is based on the Actor Model paradigm •All work in an actor model system is executed by Actors •An Actor is a single threaded entity

Communicating with Actors

• An actor is used through an ActorReference• Returned when creating an Actor

• Can be passed around

• Shields internal state

• An actor can be looked-up using an ActorSelection• Address the actor using an ActorPath (both locally as remote)

• Path can be relative (../b2)

• Path can contain wildcards (multicast)

Page 8: Web-scale Architecture NL · Actors •Akka.NET is based on the Actor Model paradigm •All work in an actor model system is executed by Actors •An Actor is a single threaded entity

Communicating with Actors

• Messages are POCO’s• Immutable

• Akka.Net offers at-most-once message delivery• So message delivery is not guaranteed!• Use explicit acks / nacks when guaranteed delivery is necessary• At-least-once semantics is possible through Akka.Persistence

Page 9: Web-scale Architecture NL · Actors •Akka.NET is based on the Actor Model paradigm •All work in an actor model system is executed by Actors •An Actor is a single threaded entity

Location transparency

• An Actor can be created in the local process or in a remote process• On the same machine of across a network on another machine

• Akka.Remote plugin

• Only the address is different, programming model is the same

• Deployment of an actor can be configured

• Different protocols available for communication• TCP

• UDP

• Your own

Page 10: Web-scale Architecture NL · Actors •Akka.NET is based on the Actor Model paradigm •All work in an actor model system is executed by Actors •An Actor is a single threaded entity

Actor Persistence

• Actors can be made persistent• Akka.Persistence plugin

• Preview version

• Based on the Event Sourcing mechanism• Journal for events that have occurred

• SnapShots for “roll-up” of events to a certain point in time

• Storage can be configured separately for Journal and Snapshot• Default: In Memory / Disk

• Contrib: SQL Server / MongoDB / Sql Lite / Event Store / Azure / … / Your Own

Page 11: Web-scale Architecture NL · Actors •Akka.NET is based on the Actor Model paradigm •All work in an actor model system is executed by Actors •An Actor is a single threaded entity

Akka.NET - 101

• This session just barely scratches the surface of the possibilities of Akka.NET

• See the documentation for more information:http://getakka.net/

• Do the Akka.NET bootcamp: https://github.com/petabridge/akka-bootcamp

Page 12: Web-scale Architecture NL · Actors •Akka.NET is based on the Actor Model paradigm •All work in an actor model system is executed by Actors •An Actor is a single threaded entity

akka.net demo

Web-scale Architecture NL

Page 13: Web-scale Architecture NL · Actors •Akka.NET is based on the Actor Model paradigm •All work in an actor model system is executed by Actors •An Actor is a single threaded entity

Demo application - Warehouse

Page 14: Web-scale Architecture NL · Actors •Akka.NET is based on the Actor Model paradigm •All work in an actor model system is executed by Actors •An Actor is a single threaded entity

WarehouseSystem

Demo application - Warehouse

Backorder Scanning

InventorySales

Page 15: Web-scale Architecture NL · Actors •Akka.NET is based on the Actor Model paradigm •All work in an actor model system is executed by Actors •An Actor is a single threaded entity

Host Process

Store Actor

WarehouseActorSystem

Demo application - Actors

Inventory Actor

Backorder Actor

Sales Actor

InventoryActor

InventoryActor

Scanner Actor

Creates Finds

/user/store

/user/store/scanner/user/store/inventory

/user/store/inventory/backorder

/user/sales

Page 16: Web-scale Architecture NL · Actors •Akka.NET is based on the Actor Model paradigm •All work in an actor model system is executed by Actors •An Actor is a single threaded entity

Demo application - ActorsStore Actor

Scanner Actor

Scanner Actor

Scanner Actor

Inventory Actor

Backorder Actor

Sales Actor

Create

Create

Look up

Create

PurchaseProduct

ScanningCompleted[scannedItems >= minimalAmountRequired]

SellProduct

BackorderProduct[stock < amount]

DumpBackorders

DumpSales

ScanItem

ScanItem

[scannedItems < minimalAmountRequired]

Host

Page 17: Web-scale Architecture NL · Actors •Akka.NET is based on the Actor Model paradigm •All work in an actor model system is executed by Actors •An Actor is a single threaded entity

Host ProcessHost Process

Store Actor

Warehouse ActorSystem

Demo application - Remoting

Inventory Actor

Backorder Actor

InventoryActor

InventoryActor

Scanner Actor

Sales ActorSystem

Sales Actor

akka.tcp://sales@localhost:9999

Creates Finds

/user/sales/user/store

/user/store/scanner/user/store/inventory

/user/store/inventory/backorder

Page 18: Web-scale Architecture NL · Actors •Akka.NET is based on the Actor Model paradigm •All work in an actor model system is executed by Actors •An Actor is a single threaded entity

Host ProcessHost Process

Store Actor

Warehouse ActorSystem

Demo application - Persistence

Inventory Actor

Backorder Actor

InventoryActor

InventoryActor

Scanner Actor

Sales ActorSystem

Sales Actor

akka.tcp://sales@localhost:9999

Creates Finds

/user/sales/user/store

/user/store/scanner/user/store/inventory

/user/store/inventory/backorder

Journal

Page 19: Web-scale Architecture NL · Actors •Akka.NET is based on the Actor Model paradigm •All work in an actor model system is executed by Actors •An Actor is a single threaded entity