Akka Java Documentation Release 2.2.3 1 Thursday, November 28, 13 - - PowerPoint PPT Presentation

akka java documentation
SMART_READER_LITE
LIVE PREVIEW

Akka Java Documentation Release 2.2.3 1 Thursday, November 28, 13 - - PowerPoint PPT Presentation

Akka Java Documentation Release 2.2.3 1 Thursday, November 28, 13 Terminology, Concepts Concurrency vs. Parallelism Asynchronous vs. Synchronous Non-blocking vs. Blocking Deadlock vs. Starvation vs. Live-lock Race Condition 2 Thursday,


slide-1
SLIDE 1

Akka Java Documentation

Release 2.2.3

1

Thursday, November 28, 13

slide-2
SLIDE 2

Terminology, Concepts

Concurrency vs. Parallelism Asynchronous vs. Synchronous Non-blocking vs. Blocking Deadlock vs. Starvation vs. Live-lock Race Condition

2

Thursday, November 28, 13

slide-3
SLIDE 3

Non-blocking Guarantees (Progress Conditions)

3

Thursday, November 28, 13

slide-4
SLIDE 4

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

slide-5
SLIDE 5

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

public void lock_free_method () { // Often calls take // finite number of steps

  • -> No deadlocks
  • -> Starvation possible

}

Thursday, November 28, 13

slide-6
SLIDE 6

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

slide-7
SLIDE 7

Supervision and Monitoring

4

Supervisor

Subordinate Subordinate Subordinate delegate tasks

Thursday, November 28, 13

slide-8
SLIDE 8

Supervision and Monitoring

4

Supervisor

Subordinate Subordinate delegate tasks Subordinate Detect failure notify

Options

  • 1. 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

slide-9
SLIDE 9

Top-Level Supervisors

5 system.actorof() akka.actor.guardian-supervisor-strategy SupervisorStrategy.stoppingStrategy ActorSystem’s status “isTerminated” = True

  • -> Orderly shut-down
  • -> Logging

Thursday, November 28, 13

slide-10
SLIDE 10

Restarting (1)

6

Causes of Actor’s Failure

Programming error for the specific message received Failure

  • f some external

resource used during processing the message Corrupt internal state

  • f actor

Thursday, November 28, 13

slide-11
SLIDE 11

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

slide-12
SLIDE 12

Lifecycle Monitoring (DeathWatch) Each actor may monitor any other actor

Useful 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)

8

Thursday, November 28, 13

slide-13
SLIDE 13

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

slide-14
SLIDE 14

Message Delivery (2)

10

message ordering per sender-receiver pair

General Rules

in-order delivery

A1 A2 A2 A3 M3, M2, M1 M6, M5, M4

this rule is not transitive

A C M1 A B M2 M2 C P Failure, M

any order

Thursday, November 28, 13

slide-15
SLIDE 15

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

slide-16
SLIDE 16

Mailbox with Explicit Acknowledgement

12

Thursday, November 28, 13

slide-17
SLIDE 17

Actors, STM and the Java Memory Model The actor send rule: The actor subsequent processing rule: The transactional reference rule:

13

Thursday, November 28, 13

slide-18
SLIDE 18

14

Thursday, November 28, 13