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, November 28, 13
Non-blocking Guarantees (Progress Conditions) 3 Thursday, November 28, 13
Non-blocking Guarantees (Progress Conditions) Wait-freedom public void wait_free_method () { // Every call takes // finite number of steps --> Never blocking (No deadlocks) --> No starvation } 3 Thursday, November 28, 13
Non-blocking Guarantees (Progress Conditions) Wait-freedom Lock-freedom public void wait_free_method () public void lock_free_method () { // Every call takes { // Often calls take // finite number of steps // finite number of steps --> Never blocking (No deadlocks) --> No deadlocks --> No starvation --> Starvation possible } } 3 Thursday, November 28, 13
Non-blocking Guarantees (Progress Conditions) Wait-freedom Lock-freedom public void wait_free_method () public void lock_free_method () { // Every call takes { // Often calls take // finite number of steps // finite number of steps --> Never blocking (No deadlocks) --> No deadlocks --> No starvation --> Starvation possible } } Obstruction-freedom public void obstruction_free_method () { // If at some point in time // it executes in isolation // (others become suspended) } 3 Thursday, November 28, 13
Supervision and Monitoring Supervisor delegate tasks Subordinate Subordinate Subordinate 4 Thursday, November 28, 13
Supervision and Monitoring Options Supervisor 1. Resume the subordinate, delegate tasks keeping its accumulated internal state Subordinate 2. Restart the subordinate, clearing out its accumulated Subordinate Detect failure internal state Subordinate notify 3. Terminate the subordinate permanently 4. Escalate the failure, thereby failing itself 4 Thursday, November 28, 13
Top-Level Supervisors ActorSystem’s status “isTerminated” = True SupervisorStrategy.stoppingStrategy --> Orderly shut-down --> Logging akka.actor.guardian-supervisor-strategy system.actorof() 5 Thursday, November 28, 13
Restarting (1) Causes of Actor’s Failure Programming error Corrupt internal state for the specific of actor message received Failure of some external resource used during processing the message 6 Thursday, November 28, 13
Restarting (2) Call the preRestart Using context.stop() Suspend the actor, hook -- Termination wait for all children and recursively request to all children which were requested suspend all children and calling postStop to terminate Send restart request Invoke postRestart Create new actor to all children which (also calls preStart by instance were not killed before default) Resume the actor 7 Thursday, November 28, 13
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
Message Delivery (1) General Rules at-most-once delivery no guaranteed delivery at-most-once -- cheapest - highest performance, least implementation overhead at-least-once -- acknowledgement exactly-once -- most expensive - worst performance 9 Thursday, November 28, 13
Message Delivery (2) General Rules this rule is not transitive message ordering per M1 A C sender-receiver pair in-order delivery M2 M2 M3, M2, M1 A B A1 A2 any order M6, M5, M4 A3 A2 Failure, M C P 10 Thursday, November 28, 13
Guaranteed Delivery ACK-RETRY Ptotocol A way to identify individual messages to correlate message with acknowledgement A retry mechanism which will resend messages if not acknowledged in time A way for the receiver to detect and discard duplicates 11 Thursday, November 28, 13
Mailbox with Explicit Acknowledgement 12 Thursday, November 28, 13
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
14 Thursday, November 28, 13
Recommend
More recommend