125
Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner http://akka.io http://typesafe.com fredag den 10 juni 2011

Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner fredag den 10 juni 2011

Embed Size (px)

Citation preview

Page 1: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

Above the Clouds:Introducing Akka

Jonas BonérCTO Typesafe

Twitter : @jbonerhttp://akka.io

http://typesafe.com

fredag den 10 juni 2011

Page 2: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

The problem

It is way too hard to build:1. correct highly concurrent systems

2. truly scalable systems

3. fault-tolerant systems that self-heals

...using “state-of-the-art” tools

fredag den 10 juni 2011

Page 3: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

akkaIntroducing

fredag den 10 juni 2011

Page 4: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

Vision

Simpler

Concurrency

Scalability

Fault-tolerance

fredag den 10 juni 2011

Page 5: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

Vision

...with a single unified

Programming model

Runtime service

fredag den 10 juni 2011

Page 6: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

Manage system overload

fredag den 10 juni 2011

Page 7: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

Scale up & Scale out

fredag den 10 juni 2011

Page 8: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

Replicate and distribute for fault-tolerance

fredag den 10 juni 2011

Page 9: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

Transparent load balancingfredag den 10 juni 2011

Page 10: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

Heavily influenced by

Erlang OTP

fredag den 10 juni 2011

Page 11: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

Concurrency

fredag den 10 juni 2011

Page 12: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

•Actors

Concurrency

fredag den 10 juni 2011

Page 13: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

•Actors•Transactional References & Data structures

Concurrency

fredag den 10 juni 2011

Page 14: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

•Actors•Transactional References & Data structures

•Agents

Concurrency

fredag den 10 juni 2011

Page 15: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

•Actors•Transactional References & Data structures

•Agents•Dataflow Concurrency

Concurrency

fredag den 10 juni 2011

Page 16: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

Remoting

fredag den 10 juni 2011

Page 17: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

Remoting

•Erlang-style supervisor hierarchies

fredag den 10 juni 2011

Page 18: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

Remoting

•Erlang-style supervisor hierarchies•Actor cluster replication

fredag den 10 juni 2011

Page 19: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

Remoting

•Erlang-style supervisor hierarchies•Actor cluster replication•Actor node migration upon failure

fredag den 10 juni 2011

Page 20: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

Fault-tolerance

fredag den 10 juni 2011

Page 21: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

•Clustered Actors

Fault-tolerance

fredag den 10 juni 2011

Page 22: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

•Clustered Actors•Data Grid

Fault-tolerance

fredag den 10 juni 2011

Page 23: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

•Clustered Actors•Data Grid•Compute Grid

Fault-tolerance

fredag den 10 juni 2011

Page 24: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

FINANCE

• Stock trend Analysis & Simulation

• Event-driven messaging systems

BETTING & GAMING

• Massive multiplayer online gaming

• High throughput and transactional betting

TELECOM

• Streaming media network gateways

SIMULATION

• 2D/3D simulation engines

E-COMMERCE

• Batch processing

• Social media community sites

SOME EXAMPLES:

WHERE IS AKKA USED?

fredag den 10 juni 2011

Page 25: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

Akka Actorsone tool in the toolbox

fredag den 10 juni 2011

Page 26: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

case class Tick(value: Int)

class Counter extends Actor { var counter = 0

def receive = { case Tick(value) => counter += value println(counter) }}

Actors

fredag den 10 juni 2011

Page 27: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

val counter = actorOf[Counter]

Create

counter is an ActorRef

fredag den 10 juni 2011

Page 28: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

counter ! Tick(1)

Send: !

fire-forget

fredag den 10 juni 2011

Page 29: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

// returns a futureval future = actor ? message

future.await

val result = future.result

Send: ?

returns the Future directly

fredag den 10 juni 2011

Page 30: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

class SomeActor extends Actor { def receive = { case User(name) => // use reply self.reply(“Hi ” + name) }}

Reply

fredag den 10 juni 2011

Page 31: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

Futureval future1, future2, future3 = Future.empty[String]

future1.onComplete(f => ...)future2.map(f => ...)future3.filter(f => ...)

future1.completeWithResult(...) future2.completeWithException(...)future3.completeWith(future2)

fredag den 10 juni 2011

Page 32: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

val f1 = Futures.future(callable)val f2 = Futures.reduce(futures)((x, y) => ..)val f3 = Futures.fold(zero)(futures)((x, y) => ...)

Future

fredag den 10 juni 2011

Page 33: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

HotSwap

self become { // new message handler case NewMessage => ... }

fredag den 10 juni 2011

Page 34: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

HotSwap

actor ! HotSwap { // new message handler case NewMessage => ... }

fredag den 10 juni 2011

Page 35: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

HotSwap

self.unbecome()

fredag den 10 juni 2011

Page 36: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

class MyActor extends Actor { self.dispatcher = Dispatchers.newPinnedDispatcher(self) ...}

actor.dispatcher = dispatcher // before started

Set dispatcher

fredag den 10 juni 2011

Page 37: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

Clustered Actors

fredag den 10 juni 2011

Page 38: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

val actor = actorOf[MyActor]

Address

Bind the actor to a virtual address

fredag den 10 juni 2011

Page 39: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

val actor = actorOf[MyActor]

Address

Bind the actor to a virtual address

(“my-service”)

fredag den 10 juni 2011

Page 40: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

akka { actor { deployment { my-service { router = "least-cpu" clustered { replicas = 3 } } } }}

Deployment configuration

fredag den 10 juni 2011

Page 41: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

Deployment

fredag den 10 juni 2011

Page 42: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

•Actor address is virtual and decoupled from how it is deployed

Deployment

fredag den 10 juni 2011

Page 43: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

•Actor address is virtual and decoupled from how it is deployed

•If no deployment configuration exists then actor is deployed as local

Deployment

fredag den 10 juni 2011

Page 44: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

•Actor address is virtual and decoupled from how it is deployed

•If no deployment configuration exists then actor is deployed as local

•The same system can be configured as distributed without code change (even change at runtime)

Deployment

fredag den 10 juni 2011

Page 45: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

•Actor address is virtual and decoupled from how it is deployed

•If no deployment configuration exists then actor is deployed as local

•The same system can be configured as distributed without code change (even change at runtime)

•Write as local but deploy as distributed in the cloud without code change

Deployment

fredag den 10 juni 2011

Page 46: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

•Actor address is virtual and decoupled from how it is deployed

•If no deployment configuration exists then actor is deployed as local

•The same system can be configured as distributed without code change (even change at runtime)

•Write as local but deploy as distributed in the cloud without code change

•Allows runtime to dynamically and adaptively change topology

Deployment

fredag den 10 juni 2011

Page 47: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

The runtime provides

fredag den 10 juni 2011

Page 48: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

•Subscription-based cluster membership service

The runtime provides

fredag den 10 juni 2011

Page 49: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

•Subscription-based cluster membership service•Highly available cluster registry for actors

The runtime provides

fredag den 10 juni 2011

Page 50: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

•Subscription-based cluster membership service•Highly available cluster registry for actors•Automatic cluster-wide deployment

The runtime provides

fredag den 10 juni 2011

Page 51: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

•Subscription-based cluster membership service•Highly available cluster registry for actors•Automatic cluster-wide deployment•Automatic replication with fail-over upon node crash

The runtime provides

fredag den 10 juni 2011

Page 52: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

•Subscription-based cluster membership service•Highly available cluster registry for actors•Automatic cluster-wide deployment•Automatic replication with fail-over upon node crash•Transparent and user-configurable load-balancing

The runtime provides

fredag den 10 juni 2011

Page 53: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

•Subscription-based cluster membership service•Highly available cluster registry for actors•Automatic cluster-wide deployment•Automatic replication with fail-over upon node crash•Transparent and user-configurable load-balancing•Transparent adaptive cluster rebalancing

The runtime provides

fredag den 10 juni 2011

Page 54: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

•Subscription-based cluster membership service•Highly available cluster registry for actors•Automatic cluster-wide deployment•Automatic replication with fail-over upon node crash•Transparent and user-configurable load-balancing•Transparent adaptive cluster rebalancing•Leader election

The runtime provides

fredag den 10 juni 2011

Page 55: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

•Subscription-based cluster membership service•Highly available cluster registry for actors•Automatic cluster-wide deployment•Automatic replication with fail-over upon node crash•Transparent and user-configurable load-balancing•Transparent adaptive cluster rebalancing•Leader election•Durable mailboxes - guaranteed delivery

The runtime provides

fredag den 10 juni 2011

Page 56: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

•Subscription-based cluster membership service•Highly available cluster registry for actors•Automatic cluster-wide deployment•Automatic replication with fail-over upon node crash•Transparent and user-configurable load-balancing•Transparent adaptive cluster rebalancing•Leader election•Durable mailboxes - guaranteed delivery•Highly available centralized configuration service

The runtime provides

fredag den 10 juni 2011

Page 57: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

•Subscription-based cluster membership service•Highly available cluster registry for actors•Automatic cluster-wide deployment•Automatic replication with fail-over upon node crash•Transparent and user-configurable load-balancing•Transparent adaptive cluster rebalancing•Leader election•Durable mailboxes - guaranteed delivery•Highly available centralized configuration service•...and more

The runtime provides

fredag den 10 juni 2011

Page 58: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

Clustering of Stateless Actor

fredag den 10 juni 2011

Page 59: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

Akka Node

fredag den 10 juni 2011

Page 60: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

Akka Node

val ping = actorOf[Ping](“ping”)val pong = actorOf[Pong](“pong”)

ping ! Ball(pong)

fredag den 10 juni 2011

Page 61: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

Akka Node

val ping = actorOf[Ping](“ping”)val pong = actorOf[Pong](“pong”)

ping ! Ball(pong)

Ping Pong

fredag den 10 juni 2011

Page 62: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

Akka Node

AkkaCluster Node

Ping Pong

fredag den 10 juni 2011

Page 63: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

Akka Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

Ping Pong

fredag den 10 juni 2011

Page 64: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

Ping Pong

fredag den 10 juni 2011

Page 65: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

akka { actor { deployment { ping {} pong { router = "round-robin" clustered { replicas = 3 } } } }}

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

Ping Pong

fredag den 10 juni 2011

Page 66: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

akka { actor { deployment { ping {} pong { router = "round-robin" clustered { replicas = 3 } } } }}

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster NodePing

Pong

fredag den 10 juni 2011

Page 67: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

akka { actor { deployment { ping {} pong { router = "round-robin" clustered { replicas = 3 } } } }}

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster NodePing

Pong

Pong

Pong

fredag den 10 juni 2011

Page 68: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

ZooKeeperZooKeeperZooKeeperEnsemble

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster NodePing

Pong

Pong

Pong

fredag den 10 juni 2011

Page 69: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster NodePing

Pong

Pong

Pong

Fail-over

Redirect references

fredag den 10 juni 2011

Page 70: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

Clustering of Stateful Actor

fredag den 10 juni 2011

Page 71: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

Replication

1Transaction log

fredag den 10 juni 2011

Page 72: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

akka { actor { deployment { carts { clustered { home = "node:test-node-1" replication { storage = "transaction-log" strategy = "write-through" } } } } }}

Deployment configuration

fredag den 10 juni 2011

Page 73: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

Akka Node

fredag den 10 juni 2011

Page 74: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

Akka Node

val carts = actorOf[CartRepository](“carts”)val client = actorOf[Pong](“client”)

fredag den 10 juni 2011

Page 75: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

Akka Node

val carts = actorOf[CartRepository](“carts”)val client = actorOf[Pong](“client”)

Client Carts

fredag den 10 juni 2011

Page 76: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

Akka Node

AkkaCluster Node

Client Carts

fredag den 10 juni 2011

Page 77: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

Akka Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

Client Carts

fredag den 10 juni 2011

Page 78: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

Client Carts

fredag den 10 juni 2011

Page 79: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

akka { actor { deployment { carts { clustered { replication { storage = "transaction-log" strategy = "write-through" } } } } }}

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

Client Carts

fredag den 10 juni 2011

Page 80: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster NodeClient

Carts

Transaction LogTransaction LogTransaction Log

fredag den 10 juni 2011

Page 81: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster NodeClient

Carts

Write behindreplication

Transaction LogTransaction LogTransaction Log

Asynchronouslogging

fredag den 10 juni 2011

Page 82: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster NodeClient

Carts

Write through replication

Client

Transaction LogTransaction LogTransaction Log

Synchronouslogging

fredag den 10 juni 2011

Page 83: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster NodeClient

Carts

Write through replication

Client

Transaction LogTransaction LogTransaction Log

fredag den 10 juni 2011

Page 84: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster NodeClient Carts

Client

Fail-over

Transaction LogTransaction LogTransaction Log

fredag den 10 juni 2011

Page 85: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster NodeClient Carts

Replay transaction log

Client

Fail-over

Transaction LogTransaction LogTransaction Log

fredag den 10 juni 2011

Page 86: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster NodeClient Carts

Client

Fail-over

Transaction LogTransaction LogTransaction Log

fredag den 10 juni 2011

Page 87: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster NodeClient Carts

Client

Fail-over

Redirect references

Transaction LogTransaction LogTransaction Log

fredag den 10 juni 2011

Page 88: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

Transaction logReplaying messages

fredag den 10 juni 2011

Page 89: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

Transaction logReplaying messages

1 2 3 4 5 6 7

fredag den 10 juni 2011

Page 90: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

Transaction logRolling Snapshot

1 2 100...

fredag den 10 juni 2011

Page 91: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

Transaction logRolling Snapshot

1 2 100...

CartsSnapshot

fredag den 10 juni 2011

Page 92: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

Transaction logRolling Snapshot

1 2 100 101 102 103 104...

CartsSnapshot

fredag den 10 juni 2011

Page 93: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

Replication

2Data Grid

fredag den 10 juni 2011

Page 94: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

Actor state•Stored in “external” Data Grid•Transactional (distributed STM)•Versioned•Replicated•QueriesImplementations•Custom Akka Data Grid•SPI for third-party Data Grids

Data Grid

fredag den 10 juni 2011

Page 95: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster NodeClient

Carts

fredag den 10 juni 2011

Page 96: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

akka { actor { deployment { carts { clustered { replicas = 3 replication { storage = "data-grid" strategy = "write-behind" } } } } }}

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster NodeClient

Carts

fredag den 10 juni 2011

Page 97: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster NodeClient

Carts

Transaction LogTransaction LogData Grid

fredag den 10 juni 2011

Page 98: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster NodeClient

Carts

Transaction LogTransaction LogData Grid

Take snapshot

Store snapshot in Data Grid

CartsCartsCarts

fredag den 10 juni 2011

Page 99: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster NodeClient

Fail-over

Transaction LogTransaction LogData Grid

Carts

CartsCartsCarts

fredag den 10 juni 2011

Page 100: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster NodeClient

Read in snapshot from Data Grid

Fail-over

Transaction LogTransaction LogData Grid

CartsCarts

CartsCarts

fredag den 10 juni 2011

Page 101: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster Node

AkkaCluster NodeClient

Fail-over

Redirect references

Transaction LogTransaction LogData Grid

Carts

CartsCarts

fredag den 10 juni 2011

Page 102: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

For power users: Cluster API

fredag den 10 juni 2011

Page 103: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

import Actor.cluster

For power users: Cluster API

fredag den 10 juni 2011

Page 104: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

import Actor.cluster

cluster.start()

For power users: Cluster API

fredag den 10 juni 2011

Page 105: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

import Actor.cluster

cluster.start() cluster.shutdown()

For power users: Cluster API

fredag den 10 juni 2011

Page 106: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

import Actor.cluster

cluster.start() cluster.shutdown()

cluster register (new ChangeListener {

For power users: Cluster API

fredag den 10 juni 2011

Page 107: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

import Actor.cluster

cluster.start() cluster.shutdown()

cluster register (new ChangeListener { def nodeConnected(node: String, client: ClusterNode) { ... }

For power users: Cluster API

fredag den 10 juni 2011

Page 108: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

import Actor.cluster

cluster.start() cluster.shutdown()

cluster register (new ChangeListener { def nodeConnected(node: String, client: ClusterNode) { ... } ...

For power users: Cluster API

fredag den 10 juni 2011

Page 109: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

import Actor.cluster

cluster.start() cluster.shutdown()

cluster register (new ChangeListener { def nodeConnected(node: String, client: ClusterNode) { ... } ... })

For power users: Cluster API

fredag den 10 juni 2011

Page 110: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

import Actor.cluster

cluster.start() cluster.shutdown()

cluster register (new ChangeListener { def nodeConnected(node: String, client: ClusterNode) { ... } ... })

cluster store actorRef

For power users: Cluster API

fredag den 10 juni 2011

Page 111: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

import Actor.cluster

cluster.start() cluster.shutdown()

cluster register (new ChangeListener { def nodeConnected(node: String, client: ClusterNode) { ... } ... })

cluster store actorRef cluster remove actorAddress

For power users: Cluster API

fredag den 10 juni 2011

Page 112: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

import Actor.cluster

cluster.start() cluster.shutdown()

cluster register (new ChangeListener { def nodeConnected(node: String, client: ClusterNode) { ... } ... })

cluster store actorRef cluster remove actorAddress

val actorRef = cluster use actorAddress

For power users: Cluster API

fredag den 10 juni 2011

Page 113: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

import Actor.cluster

cluster.start() cluster.shutdown()

cluster register (new ChangeListener { def nodeConnected(node: String, client: ClusterNode) { ... } ... })

cluster store actorRef cluster remove actorAddress

val actorRef = cluster use actorAddress val actorRef = cluster ref (actorAddress, router)

For power users: Cluster API

fredag den 10 juni 2011

Page 114: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

import Actor.cluster

cluster.start() cluster.shutdown()

cluster register (new ChangeListener { def nodeConnected(node: String, client: ClusterNode) { ... } ... })

cluster store actorRef cluster remove actorAddress

val actorRef = cluster use actorAddress val actorRef = cluster ref (actorAddress, router)

cluster migrate (fromNode, toNode, actorAddress)

For power users: Cluster API

fredag den 10 juni 2011

Page 115: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

import Actor.cluster

cluster.start() cluster.shutdown()

cluster register (new ChangeListener { def nodeConnected(node: String, client: ClusterNode) { ... } ... })

cluster store actorRef cluster remove actorAddress

val actorRef = cluster use actorAddress val actorRef = cluster ref (actorAddress, router)

cluster migrate (fromNode, toNode, actorAddress)

cluster send (() => { ... }, nrReplicas) map (_.result)

For power users: Cluster API

fredag den 10 juni 2011

Page 116: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

•Direct•Random•Round robin•Least CPU (soon)•Least RAM (soon)•Least messages (soon)•Custom

Routers

fredag den 10 juni 2011

Page 117: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

•File-based•Redis-based•Beanstalk-based•MongoDB-based•ZooKeeper-based•Cassandra-based (soon)•AMQP-based (soon)•JMS-based (soon)

Durable Mailboxes

fredag den 10 juni 2011

Page 118: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

Clustering of Akka 2.0ETA mid fall

fredag den 10 juni 2011

Page 119: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

Learn morehttp://akka.io

http://typesafe.com

fredag den 10 juni 2011

Page 120: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

EOFfredag den 10 juni 2011

Page 121: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

Let it crash fault-tolerance

fredag den 10 juni 2011

Page 122: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

link(actor)unlink(actor)

startLink(actor)spawnLink[MyActor]

Linking

fredag den 10 juni 2011

Page 123: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

AllForOneStrategy( errors, maxNrOfRetries, withinTimeRange)

OneForOneStrategy( errors, maxNrOfRetries, withinTimeRange)

Fault handlers

fredag den 10 juni 2011

Page 124: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

class  Supervisor  extends  Actor  {    faultHandler  =  AllForOneStrategy(        List(classOf[IllegalStateException])          5,  5000))

   def  receive  =  {        case  Register(actor)  =>  link(actor)    }}

Supervision

fredag den 10 juni 2011

Page 125: Above the Clouds: Introducing Akka - erlang … · Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner   fredag den 10 juni 2011

class FaultTolerantService extends Actor { ... override def preRestart(reason: Throwable) = { ... // clean up before restart } override def postRestart(reason: Throwable) = { ... // init after restart }}

Manage failure

fredag den 10 juni 2011