18
Akka Java Documentation Release 2.2.3 1 Thursday, November 28, 13

Akka Java Documentation - Lunds tekniska högskola

  • Upload
    others

  • View
    7

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Akka Java Documentation - Lunds tekniska högskola

Akka Java DocumentationRelease 2.2.3

1Thursday, November 28, 13

Page 2: Akka Java Documentation - Lunds tekniska högskola

Terminology, Concepts

Concurrency vs. ParallelismAsynchronous vs. SynchronousNon-blocking vs. BlockingDeadlock vs. Starvation vs. Live-lockRace Condition

2Thursday, November 28, 13

Page 3: Akka Java Documentation - Lunds tekniska högskola

Non-blocking Guarantees (Progress Conditions)

3Thursday, November 28, 13

Page 4: Akka Java Documentation - Lunds tekniska högskola

Non-blocking Guarantees (Progress Conditions)

Wait-freedom

3

public void wait_free_method (){ // Every call takes

// finite number of steps--> Never blocking (No deadlocks)--> No starvation

}

Thursday, November 28, 13

Page 5: Akka Java Documentation - Lunds tekniska högskola

Non-blocking Guarantees (Progress Conditions)

Wait-freedom

3

public void wait_free_method (){ // Every call takes

// finite number of steps--> Never blocking (No deadlocks)--> No starvation

}

Lock-freedompublic void lock_free_method (){ // Often calls take

// finite number of steps--> No deadlocks--> Starvation possible

}

Thursday, November 28, 13

Page 6: Akka Java Documentation - Lunds tekniska högskola

Non-blocking Guarantees (Progress Conditions)

Wait-freedom

3

public void wait_free_method (){ // Every call takes

// finite number of steps--> Never blocking (No deadlocks)--> No starvation

}

Lock-freedom

Obstruction-freedom

public void lock_free_method (){ // Often calls take

// finite number of steps--> No deadlocks--> Starvation possible

}

public void obstruction_free_method (){ // If at some point in time

// it executes in isolation // (others become suspended)

}

Thursday, November 28, 13

Page 7: Akka Java Documentation - Lunds tekniska högskola

Supervision and Monitoring

4

Supervisor

SubordinateSubordinate

Subordinate

delegate tasks

Thursday, November 28, 13

Page 8: Akka Java Documentation - Lunds tekniska högskola

Supervision and Monitoring

4

Supervisor

Subordinate

Subordinate

delegate tasks

SubordinateDetect failure

notify

Options1. Resume the subordinate, keeping its accumulated internal state 2. Restart the subordinate, clearing out its accumulated internal state

3. Terminate the subordinate permanently

4. Escalate the failure, thereby failing itself

Thursday, November 28, 13

Page 9: Akka Java Documentation - Lunds tekniska högskola

Top-Level Supervisors

5system.actorof()

akka.actor.guardian-supervisor-strategy

SupervisorStrategy.stoppingStrategyActorSystem’s status “isTerminated” = True

--> Orderly shut-down--> Logging

Thursday, November 28, 13

Page 10: Akka Java Documentation - Lunds tekniska högskola

Restarting (1)

6

Causes of Actor’s Failure

Programming error for the specific

message receivedFailure

of some external resource used during

processing the message

Corrupt internal state of actor

Thursday, November 28, 13

Page 11: Akka Java Documentation - Lunds tekniska högskola

Restarting (2)

7

Suspend the actor, and recursively

suspend all children

Call the preRestart hook -- Termination

request to all children and calling postStop

Using context.stop() wait for all children

which were requested to terminate

Create new actor instance

Invoke postRestart (also calls preStart by

default)

Send restart request to all children which were not killed before

Resume the actor

Thursday, November 28, 13

Page 12: Akka Java Documentation - Lunds tekniska högskola

Lifecycle Monitoring (DeathWatch)

Each actor may monitor any other actorUseful in the cases when supervisors have to terminate the children

Restarts are not visible outside the affected supervisors

Transition from Alive to Dead can be only monitored using Terminated message

ActorContext.watch(targetActorRef)

ActorContext.unwatch(targetActorRef)

8Thursday, November 28, 13

Page 13: Akka Java Documentation - Lunds tekniska högskola

Message Delivery (1)

9

at-most-once delivery

General Rules

no guaranteed delivery

at-most-once -- cheapest - highest performance, least implementation overhead

at-least-once -- acknowledgement

exactly-once -- most expensive - worst performance

Thursday, November 28, 13

Page 14: Akka Java Documentation - Lunds tekniska högskola

Message Delivery (2)

10

message ordering per sender-receiver pair

General Rules

in-order delivery

A1 A2

A2A3

M3, M2, M1

M6, M5, M4

this rule is not transitive

A CM1

A BM2

M2

C PFailure, Many order

Thursday, November 28, 13

Page 15: Akka Java Documentation - Lunds tekniska högskola

Guaranteed Delivery

11

A way to identify individual messages to correlate message

with acknowledgement

ACK-RETRY Ptotocol

A retry mechanism which will resend messages if not acknowledged in time

A way for the receiver to detect and discard duplicates

Thursday, November 28, 13

Page 16: Akka Java Documentation - Lunds tekniska högskola

Mailbox with Explicit Acknowledgement

12Thursday, November 28, 13

Page 17: Akka Java Documentation - Lunds tekniska högskola

Actors, STM and the Java Memory Model

The actor send rule:The actor subsequent processing rule:

The transactional reference rule:

13Thursday, November 28, 13

Page 18: Akka Java Documentation - Lunds tekniska högskola

14Thursday, November 28, 13