reactive applications with akka.net - ddd east anglia 2015

110
Reactive Applications with akka.Net Anthony Brown @bruinbrown93 me@anthonyjbrown.co.uk

Upload: anthony-brown

Post on 15-Apr-2017

1.697 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: Reactive applications with Akka.Net - DDD East Anglia 2015

Reactive Applications with akka.Net

Anthony Brown

@bruinbrown93

[email protected]

Page 2: Reactive applications with Akka.Net - DDD East Anglia 2015

HI, I’m Anthony

Software engineer at Adbrain

[email protected]

@bruinbrown93

Page 3: Reactive applications with Akka.Net - DDD East Anglia 2015

Computers have changed… A lot

Page 4: Reactive applications with Akka.Net - DDD East Anglia 2015
Page 5: Reactive applications with Akka.Net - DDD East Anglia 2015
Page 6: Reactive applications with Akka.Net - DDD East Anglia 2015
Page 7: Reactive applications with Akka.Net - DDD East Anglia 2015
Page 8: Reactive applications with Akka.Net - DDD East Anglia 2015

Some of the changes

Faster processors More processor cores

More RAM Faster networks with more bandwidth

Page 9: Reactive applications with Akka.Net - DDD East Anglia 2015

We need to make sure applications are responsive to user actions

Page 10: Reactive applications with Akka.Net - DDD East Anglia 2015

Moore’s Law

Page 11: Reactive applications with Akka.Net - DDD East Anglia 2015

Scale up no longer possible

Page 12: Reactive applications with Akka.Net - DDD East Anglia 2015

What’s the options?

Page 13: Reactive applications with Akka.Net - DDD East Anglia 2015

CPUs have more cores Networks are faster

Page 14: Reactive applications with Akka.Net - DDD East Anglia 2015

Scale out is now possible

Page 15: Reactive applications with Akka.Net - DDD East Anglia 2015

Scale out relies on doing lots of work simultaneously

Page 16: Reactive applications with Akka.Net - DDD East Anglia 2015

To do work simultaneously, we need either parallelism or concurrency

Page 17: Reactive applications with Akka.Net - DDD East Anglia 2015

Parallelism is easy for Embarrassingly parallel tasks

Page 18: Reactive applications with Akka.Net - DDD East Anglia 2015

For more complex tasks, we need concurrency

Page 19: Reactive applications with Akka.Net - DDD East Anglia 2015

Is there a difference?

Page 20: Reactive applications with Akka.Net - DDD East Anglia 2015

Concurrency

Parallelism

Thread 1

Thread 2

Thread 1

Thread 2

Page 21: Reactive applications with Akka.Net - DDD East Anglia 2015

Concurrency is hard

Page 22: Reactive applications with Akka.Net - DDD East Anglia 2015

MULTITHREADING

THEORYPRACTICE

Page 23: Reactive applications with Akka.Net - DDD East Anglia 2015

CHECK OUTMY MULTITHREADED CODE

Page 24: Reactive applications with Akka.Net - DDD East Anglia 2015

HOW MANY THREADSDOES IT TAKE TO CHANGE A LIGHTBULB?

Page 25: Reactive applications with Akka.Net - DDD East Anglia 2015

We don’t want to write multithreaded code

Page 26: Reactive applications with Akka.Net - DDD East Anglia 2015

Use concurrency abstractions instead

Page 27: Reactive applications with Akka.Net - DDD East Anglia 2015

You’ve probably used one Tasks

Page 28: Reactive applications with Akka.Net - DDD East Anglia 2015

There’s another - actors

Page 29: Reactive applications with Akka.Net - DDD East Anglia 2015
Page 30: Reactive applications with Akka.Net - DDD East Anglia 2015

Why are tasks bad?

Page 31: Reactive applications with Akka.Net - DDD East Anglia 2015

They’re not, they solve a different problem

Page 32: Reactive applications with Akka.Net - DDD East Anglia 2015

Promote isolation over co-ordination

Page 33: Reactive applications with Akka.Net - DDD East Anglia 2015

Actors are independent entities

Page 34: Reactive applications with Akka.Net - DDD East Anglia 2015

Why does this matter?

Page 35: Reactive applications with Akka.Net - DDD East Anglia 2015

We said we need applications to be responsive

Page 36: Reactive applications with Akka.Net - DDD East Anglia 2015

What does it mean for an application to be responsive?

Page 37: Reactive applications with Akka.Net - DDD East Anglia 2015

For an application to be responsive, it needs to work no matter what

the scenario

Page 38: Reactive applications with Akka.Net - DDD East Anglia 2015

Heavy load

Page 39: Reactive applications with Akka.Net - DDD East Anglia 2015

Service failure

Page 40: Reactive applications with Akka.Net - DDD East Anglia 2015

If we want to manage these, we need loose coupling

Page 41: Reactive applications with Akka.Net - DDD East Anglia 2015

Common language for these applications

Page 42: Reactive applications with Akka.Net - DDD East Anglia 2015

Reactive reactivemanifesto.org

Page 43: Reactive applications with Akka.Net - DDD East Anglia 2015

RESPONSIVE

RESILIENT ELASTIC

MESSAGE PASSING

Page 44: Reactive applications with Akka.Net - DDD East Anglia 2015

Reactive applications React to their environment

Page 45: Reactive applications with Akka.Net - DDD East Anglia 2015
Page 46: Reactive applications with Akka.Net - DDD East Anglia 2015

using actors to write reactive applications

Page 47: Reactive applications with Akka.Net - DDD East Anglia 2015

an actor is

A mailbox behaviour state

Page 48: Reactive applications with Akka.Net - DDD East Anglia 2015

We saw that actors are strongly isolated, they encapsulate their

state

Page 49: Reactive applications with Akka.Net - DDD East Anglia 2015

To modify the state, we have a behaviour which is responsible for

it

Page 50: Reactive applications with Akka.Net - DDD East Anglia 2015

We invoke the behaviour by sending it a message

Page 51: Reactive applications with Akka.Net - DDD East Anglia 2015

Messages are processed serially but on separate threads

Page 52: Reactive applications with Akka.Net - DDD East Anglia 2015

An actor can

send a finite number of messages

Page 53: Reactive applications with Akka.Net - DDD East Anglia 2015

An actor can

spawn a finite number of actors

Page 54: Reactive applications with Akka.Net - DDD East Anglia 2015

An actor can

change how it responds to the next message

Page 55: Reactive applications with Akka.Net - DDD East Anglia 2015

How can we write actors?

Page 56: Reactive applications with Akka.Net - DDD East Anglia 2015

Using akka.Net

Page 57: Reactive applications with Akka.Net - DDD East Anglia 2015
Page 58: Reactive applications with Akka.Net - DDD East Anglia 2015

Step 1 Define an actor

Page 59: Reactive applications with Akka.Net - DDD East Anglia 2015

class  GreetingActor  :  ReceiveActor  {          public  GreetingActor()          {                  Receive<string>(                          s  =>  Console.WriteLine(“Hello  ”  +  s));          }  }

Page 60: Reactive applications with Akka.Net - DDD East Anglia 2015

Step 2 Create an actor system

Page 61: Reactive applications with Akka.Net - DDD East Anglia 2015

var  system  =  ActorSystem.Create(“GreeterSystem”);

Page 62: Reactive applications with Akka.Net - DDD East Anglia 2015

Step 3 Spawn the actor

Page 63: Reactive applications with Akka.Net - DDD East Anglia 2015

var  greeterActor  =  system.ActorOf<GreeterActor>();

Page 64: Reactive applications with Akka.Net - DDD East Anglia 2015

where is my actual actor?

AKKA.net

root actor

your

actors

Page 65: Reactive applications with Akka.Net - DDD East Anglia 2015

Step 4 Talk to the actor

Page 66: Reactive applications with Akka.Net - DDD East Anglia 2015

greeter.Tell(“DDDEA”);

Page 67: Reactive applications with Akka.Net - DDD East Anglia 2015

What about F#?

Page 68: Reactive applications with Akka.Net - DDD East Anglia 2015

Full F# API

Page 69: Reactive applications with Akka.Net - DDD East Anglia 2015

Built upon Erlang foundations

Page 70: Reactive applications with Akka.Net - DDD East Anglia 2015

let  Actor  count  =          actor  {                  let!  msg  =  mailbox.Receive  ()                  printfn  “Message  %i:  %A”  count  msg                  return!  actor  (count+1)          }

Page 71: Reactive applications with Akka.Net - DDD East Anglia 2015

Resilience in distributed

systems

Page 72: Reactive applications with Akka.Net - DDD East Anglia 2015

Cloud brings about failure

Page 73: Reactive applications with Akka.Net - DDD East Anglia 2015

your users don’t want to see THIS

Page 74: Reactive applications with Akka.Net - DDD East Anglia 2015

Need to isolate failures quickly and automatically recover from

them

Page 75: Reactive applications with Akka.Net - DDD East Anglia 2015

How can we isolate errors?

Page 76: Reactive applications with Akka.Net - DDD East Anglia 2015

Separate error channels

Page 77: Reactive applications with Akka.Net - DDD East Anglia 2015

Service aService B

supervisor

Request

Response

user error

error action

Page 78: Reactive applications with Akka.Net - DDD East Anglia 2015

Handling increased load in a

distributed system

Page 79: Reactive applications with Akka.Net - DDD East Anglia 2015

Easiest way to scale is to make the servers bigger

Page 80: Reactive applications with Akka.Net - DDD East Anglia 2015

Scale up has a limit, scale out doesn't

Page 81: Reactive applications with Akka.Net - DDD East Anglia 2015

Scale out is easy with isolation

Page 82: Reactive applications with Akka.Net - DDD East Anglia 2015

Actors give us isolation therefore scalability is easy with actors

Page 83: Reactive applications with Akka.Net - DDD East Anglia 2015

Routers

Page 84: Reactive applications with Akka.Net - DDD East Anglia 2015

Taking akka.Net to the next

level

Page 85: Reactive applications with Akka.Net - DDD East Anglia 2015

Akka.Remote

Page 86: Reactive applications with Akka.Net - DDD East Anglia 2015

Connecting 2 actor systems in a client-server architecture

Page 87: Reactive applications with Akka.Net - DDD East Anglia 2015

Akka.Cluster

Page 88: Reactive applications with Akka.Net - DDD East Anglia 2015

Takes remoting to the next level

Page 89: Reactive applications with Akka.Net - DDD East Anglia 2015

Treat multiple machines as one actor system

Page 90: Reactive applications with Akka.Net - DDD East Anglia 2015

Cluster aware routers

Page 91: Reactive applications with Akka.Net - DDD East Anglia 2015

Cluster sharding

Page 92: Reactive applications with Akka.Net - DDD East Anglia 2015

Akka.Persistence

Page 93: Reactive applications with Akka.Net - DDD East Anglia 2015

Allows for easy CQRS and Event sourcing with actors

Page 94: Reactive applications with Akka.Net - DDD East Anglia 2015

Akka.DistributedData

Page 95: Reactive applications with Akka.Net - DDD East Anglia 2015

Allows for sharing data between actors with strong eventual

consistency

Page 96: Reactive applications with Akka.Net - DDD East Anglia 2015

Where can I use akka.Net?

Page 97: Reactive applications with Akka.Net - DDD East Anglia 2015

IoT applications

Page 98: Reactive applications with Akka.Net - DDD East Anglia 2015

Job scheduling / cluster management

Page 99: Reactive applications with Akka.Net - DDD East Anglia 2015

Gaming

Page 100: Reactive applications with Akka.Net - DDD East Anglia 2015

User interfaces

Page 101: Reactive applications with Akka.Net - DDD East Anglia 2015

Microservices deployments

Page 102: Reactive applications with Akka.Net - DDD East Anglia 2015

akka.Net provides a solid foundation for the stronger constraints being

imposed today and in the future

Page 103: Reactive applications with Akka.Net - DDD East Anglia 2015

Want to learn more?

Page 104: Reactive applications with Akka.Net - DDD East Anglia 2015

akka.Net bootcamp github.com/petabridge/akka-bootcamp

Page 105: Reactive applications with Akka.Net - DDD East Anglia 2015

Reactive applications with akka.Net MEAP soon

Page 106: Reactive applications with Akka.Net - DDD East Anglia 2015

StackOverflow stackoverflow.com/tags/akka.net

Page 107: Reactive applications with Akka.Net - DDD East Anglia 2015

Want to contribute?

Page 108: Reactive applications with Akka.Net - DDD East Anglia 2015

Plenty of up for grabs issues github.com/akkadotnet/akka.net

Page 109: Reactive applications with Akka.Net - DDD East Anglia 2015

gitter.im/akkadotnet/akka.net

Page 110: Reactive applications with Akka.Net - DDD East Anglia 2015

Q & A