Akka Building Distributed Systems for Concurrent, Fault-tolerant - - PowerPoint PPT Presentation

akka
SMART_READER_LITE
LIVE PREVIEW

Akka Building Distributed Systems for Concurrent, Fault-tolerant - - PowerPoint PPT Presentation

Akka Building Distributed Systems for Concurrent, Fault-tolerant and Scalable Java Applications 1 Thursday, November 21, 13 1 Problems with Multithreaded Programming Shared Mutable Objects Thread 2 Thread 1 Solution: Synchronized Access


slide-1
SLIDE 1

Akka

Building Distributed Systems for Concurrent, Fault-tolerant and Scalable Java Applications

1

1 Thursday, November 21, 13

slide-2
SLIDE 2

Problems with Multithreaded Programming

Shared Objects

Thread 2 Thread 1

Shared Mutable Objects

Solution: Synchronized Access (guarded by locks) 2

2 Thursday, November 21, 13

slide-3
SLIDE 3

Problems with Multithreaded Programming

Shared Objects

Thread 2 Thread 1

Shared Mutable Objects

Solution: Synchronized Access (guarded by locks) 2 Change in one part of the system may break it in another part.

2 Thursday, November 21, 13

slide-4
SLIDE 4

Problems with Multithreaded Programming

Shared Objects

Thread 2 Thread 1

Shared Mutable Objects

Solution: Synchronized Access (guarded by locks)

  • 1. Operations may occur serially -> poor performance
  • 2. Locks
  • - do not compose -> hard to design applications
  • - do not scale well -> block the execution
  • - hard to get in right order and error recovery is complicated

2 Change in one part of the system may break it in another part.

2 Thursday, November 21, 13

slide-5
SLIDE 5

Problems with Multithreaded Programming

3

Shared block 1

Thread 2 Thread 1

Deadlocks

Thread 1 has obtained the lock to synchronized block 1 and Thread 2 has obtained the lock to synchronized block 2

Shared block 2

Synchronized

3 Thursday, November 21, 13

slide-6
SLIDE 6

Problems with Multithreaded Programming

4

Scalability

Managing multiple threads in a single JVM Challenging Scaling the application across multiple JVMs?

4 Thursday, November 21, 13

slide-7
SLIDE 7

Problems with Multithreaded Programming

4

Scalability

Managing multiple threads in a single JVM Challenging Scaling the application across multiple JVMs? Shared state stored in database and Relying on database to manage the concurrent access

4 Thursday, November 21, 13

slide-8
SLIDE 8

Akka: A Solution for Concurrency, Fault-tolerance and Scalability

5

Open source toolkit and runtime that runs on JVM May use Scala or Java to call libraries and features Written in Scala High level abstraction for concurrency: Actors combined with software transaction memory (SMT) to implement atomic message-passing

5 Thursday, November 21, 13

slide-9
SLIDE 9

Actors in Akka

6

Actors

(lightweight processes) Simple and high-level abstraction for concurrency and parallelism Asynchronous, non- blocking, and high- performance event-driven programming Provide Support Implement share nothing architecture and encapsulate state and behavior state change is local

6 Thursday, November 21, 13

slide-10
SLIDE 10

“Let it Crash” Model for Fault-tolerance

7

standard java application

try { } catch (ExceptionType name) { } catch (ExceptionType name) { } critically important state is guarded by try/catch blocks

7 Thursday, November 21, 13

slide-11
SLIDE 11

“Let it Crash” Model for Fault-tolerance

7

standard java application

try { } catch (ExceptionType name) { } catch (ExceptionType name) { } critically important state is guarded by try/catch blocks

Akka

actor P actor C supervisor of actor C

supervisor hierarchy

7 Thursday, November 21, 13

slide-12
SLIDE 12

“Let it Crash” Model for Fault-tolerance

7

standard java application

try { } catch (ExceptionType name) { } catch (ExceptionType name) { } critically important state is guarded by try/catch blocks

Akka

actor P actor C supervisor of actor C

supervisor hierarchy

Crash

Notify

7 Thursday, November 21, 13

slide-13
SLIDE 13

The Actor Model

8

8 Thursday, November 21, 13

slide-14
SLIDE 14

The Actor Model

8

ActorSystem ActorRef

MessageDispatcher

Mailbox Actor Message Queue

Creates Dispatch Runs Publishes Message Invokes Retrieves Message

8 Thursday, November 21, 13

slide-15
SLIDE 15

Some More Advantages

9

  • - can maintain a thread pool having

limited number of threads.

  • - can be configured with one-to-one

mapping of threads to actors.

MessageDispatcher

Load balancing

9 Thursday, November 21, 13

slide-16
SLIDE 16

Some More Advantages

9

  • - can maintain a thread pool having

limited number of threads.

  • - can be configured with one-to-one

mapping of threads to actors.

MessageDispatcher

Load balancing

ActorRef

Horizontal scalability

Local ActorRef Remote ActorRef

9 Thursday, November 21, 13

slide-17
SLIDE 17

Actor Hierarchies

10

system hierarchy

Actor hierarchy ActorSystem.Actors

user hierarchy

root actor: Guardian top-level actors child actors

10 Thursday, November 21, 13

slide-18
SLIDE 18

Example: Computing Prime Numbers Create a master actor Create a round-robin router to distribute work across multiple worker actors Communicate between worker actors and the master actor Communicate between the master actor and a listner

11

11 Thursday, November 21, 13

slide-19
SLIDE 19

12

12 Thursday, November 21, 13

slide-20
SLIDE 20

13

13 Thursday, November 21, 13

slide-21
SLIDE 21

14

14 Thursday, November 21, 13

slide-22
SLIDE 22

15

15 Thursday, November 21, 13

slide-23
SLIDE 23

15

15 Thursday, November 21, 13

slide-24
SLIDE 24

16

16 Thursday, November 21, 13

slide-25
SLIDE 25

17

17 Thursday, November 21, 13

slide-26
SLIDE 26

Exercise

Find GCD for a given set of numbers by creating 2 worker_actors and dividing the load among them equally. Report the time for computation taken by each worker_actor. Use Akka release 2.2.1

18

18 Thursday, November 21, 13

slide-27
SLIDE 27

19

19 Thursday, November 21, 13