Introduction to Akka

32
Actors An introduction to Johan Andrén [email protected] | @apnylle Akka with

description

The topconf 2013 introduction to actors with Akka

Transcript of Introduction to Akka

Page 1: Introduction to Akka

ActorsAn introduction to

Johan Andrén [email protected] | @apnylle

Akka with

Page 2: Introduction to Akka

Moores law

1971 today19902300

2,6 billions

1 million

Page 3: Introduction to Akka

Oh, No Problems!

Page 4: Introduction to Akka

Oh No, Problems!

• Race conditions

• Data corruption

• Deadlocks

• Thread contention

• Livelocks

• Priority Inversion

Page 5: Introduction to Akka

Concurrency is HARD• To write

• To test

• To debug

• To reason about

We need a better model!

Page 6: Introduction to Akka
Page 7: Introduction to Akka

A

B C

D

EF

Page 8: Introduction to Akka

ACTORSevent drivensystems with

Page 9: Introduction to Akka
Page 10: Introduction to Akka

Inbox

Behaviour

State

The only way to interact from

outside

Page 11: Introduction to Akka

• Single execution flow model

• No shared _mutable_ state

• Lightweight

• Loose coupling

• Easy to test

Page 12: Introduction to Akka

Actor A Actor B

Page 13: Introduction to Akka

Actor A Actor B

One way communication

Page 14: Introduction to Akka

Actor A Actor B

React, don’t wait

Page 15: Introduction to Akka

Actor AActor B1

Load balancing

Actor B2

router

Page 16: Introduction to Akka

Actor A Actor F (filter)

Pipe/Filter

Actor B

Page 17: Introduction to Akka

Actor A Actor B (chef)

ParallellizeActor C1

Actor C2

Actor C2

Page 18: Introduction to Akka

• No work, no thread used!

• Async - never actively wait

• Loose coupling

Page 19: Introduction to Akka

A

B C

D

EF

JVM

Page 20: Introduction to Akka

A

B C

D

EF

JVM 1 JVM 2

Page 21: Introduction to Akka

• Two actors on one core

• Two actors on separate cores

• Two actors on separate servers

The same same

Page 22: Introduction to Akka

Error handlingin Actor systems

Page 23: Introduction to Akka
Page 24: Introduction to Akka

• Leaking information between tiers

• Impossible to detect simultaneous errors

• The receiver does not know how to handle the errors!

Traditional model

Page 25: Introduction to Akka

Actor X

(parent)

Actor A

Actor Z

Error handling with Actors

Page 26: Introduction to Akka

Actor X

(parent)

Actor A

Actor Z

Error handling with Actors

Page 27: Introduction to Akka

Actor X

Actor A

Actor Z

Error handling with Actors

Page 28: Introduction to Akka

• Compartmentilization

• What goes back is explicit

• Separating error handling and business logic

• Can detect simultaneous errors

”Supervision”

Page 29: Introduction to Akka

• STM

• Remoting

• Clustring with no SPoF

• MQs integration

• Eventbus

Wait, there is more!

akka.ioWebsite:

But

Page 30: Introduction to Akka

Try it out! typesafe.comTypesafe Activator

Page 31: Introduction to Akka

• Simple but powerful model

• Lightweight and fast

• Loose coupling

• Resiliency

Recap

Johan Andrén [email protected] | @apnylle

Page 32: Introduction to Akka

Questions?

Johan Andrén [email protected] | @apnylle