63
@petabridge Petabridge.com www.baynetug.org Concurrency, Without the Pain: An Intro to Akka.NET & the Actor Model with Andrew Skotzko

Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

Embed Size (px)

Citation preview

Page 1: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

www.baynetug.org

Concurrency, Without the Pain: An Intro to Akka.NET

& the Actor Model with Andrew Skotzko

Page 2: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

•  www.baynetug.org •  @baynetug / #BayNetUG •  An open and independent forum for evaluating and

extending knowledge of .NET architecture, technologies, tools and business applications

•  Monthly events (technical, business, networking) – Mountain View, San Francisco, Berkeley

•  Working groups

 

Bay.NET User Group

Page 3: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

.NET Community

San Francisco SQL Server User Group meetup.com/The-San-Francisco-SQL-Server-Meetup-Group

Azure Developers www.bayazure.org

San Francisco F# h"p://www.meetup.com/sfsharp/

Page 4: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

Coming Soon

•  San Francisco: Hello DocumentDB – Tuesday, September 15th – Microsoft, 555 California St

•  SouthBay.Net: Unit Testing Makes Me Faster: 8/27 – German International School of SV

•  Silicon Valley Code Camp: 10/3-4

– Evergreen Valley College

Page 5: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

Concurrency Without the Pain

An Intro to Akka.NET & Actor Model

#AkkaDotNet @ #BayNetUG

Andrew  Skotzko  Co-­‐founder  —  Petabridge  

Page 6: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

Why  should  we  care  about  

concurrency?  

Page 7: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

1970  -­‐  2005  

Page 8: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

Page 9: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

Page 10: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

Page 11: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

Page 12: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

Page 13: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

Page 14: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

TANSTAAFL  “There  ain’t  no  such  thing  as  a  free  lunch.”  —R.  A.  Heinlein,  The  Moon  Is  a  Harsh  Mistress  

Page 15: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

What  the  hell  are  you  talking  about?  

Page 16: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

Concurrency.  

We  needs  it.  

Page 17: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

So  why  is  this  hard?  

Page 18: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

How to Write Multithreaded Code

Page 19: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

Shared State Programming Sucks (Illustrated)

Page 20: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

Random?

•  .NET 4.0: TPL (2010) •  .NET 4.5: async/await (2012)

Page 21: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

Is there a better way? THERE MUST BE! THERE.  MUST.  BE.  A.  BETTER.  WAY!  

Page 22: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

Warning! Mind Blowingly Different

Programming Style Ahead!

Page 23: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

Warning! Mind Blowingly Different Programming Style Ahead!

Page 24: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

The Actor Model

Page 25: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

What  is  the  actor  model?  

Page 26: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

Everything  is  an  actor.  

Page 27: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

Page 28: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

Page 29: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

3 Core Abilities

1.  Send  messages  2. Create  other  actors  3. Change  behavior  

Page 30: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

Messages

Page 31: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

Actors work by passing each other messages

Page 32: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

Message passing in action

Page 33: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

BUZZWORD  BINGO!  

Page 34: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

Example Akka.NET Message

Page 35: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

Actors send messages to addresses

Page 36: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

Actor addresses have location transparency

Page 37: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

Which means…

Page 38: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

Page 39: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

Page 40: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

ReactiveManifesto.org

Page 41: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

What is Akka.NET?

Page 42: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

Battle-Tested (JVM)

Page 43: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

This is an actor

Page 44: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

These are messages

Page 45: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

Actors run on threads

Page 46: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

Actors are lazy

Page 47: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

Process messages one at a time

Page 48: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

The circle of life

Page 49: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

Page 50: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

Hierarchies

Page 51: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

Supervision

Page 52: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

Switchable Behavior

Page 53: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

And Can Form Highly Available Systems

Page 54: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

What’s  this  give  me?  

Page 55: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

Where can I use this? •  Analytics systems •  Marketing automation •  Multi-player games •  Device / IoT tracking •  Alerting & monitoring systems •  Recommendation engines •  Dynamic pricing •  Microservices •  Reactive UI

Page 56: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

DEMO  

Page 57: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

hZp://LearnAkka.net  

Page 58: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

THANK YOU!

Email:  [email protected]    

TwiZerz:    @askotzko  

@AkkaDotNet  

Page 59: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

Hierarchies pt. deux

Page 60: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

Character Actor Pattern

Page 61: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

ActorSelection == selection by address

Page 62: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

Actor lifecycle

Page 63: Concurrency, Without the Pain: An Intro to Akka.NET @ Bay.NET

@petabridge Petabridge.com

Actor lifecycle