real world akka actor recipes javaone 2013
DESCRIPTION
Patterns for actor based programs presented at JavaOne2013.TRANSCRIPT
![Page 1: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/1.jpg)
Real -World Akka Actor RecipesBjörn Antonsson
@bantonsson
co-authored with
Jamie Allen and Patrik Nordwall
Tuesday, 1 October 13
![Page 2: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/2.jpg)
@bantonsson@bantonsson
Overview
• What is Akka?• What are actors?• Getting into the flow• Getting your message across• Tying it all together
2
Tuesday, 1 October 13
![Page 3: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/3.jpg)
What is Akka?
Tuesday, 1 October 13
![Page 4: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/4.jpg)
@bantonsson@bantonsson
What is Akka?
• Toolkit and runtime for reactive applications• Write applications that are– Concurrent– Distributed– Fault tolerant– Event-driven
4
Tuesday, 1 October 13
![Page 5: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/5.jpg)
@bantonsson@bantonsson
What is Akka?
• Has multiple tools– Actors– Futures– Dataflow– Remoting– Clustering
5
Tuesday, 1 October 13
![Page 6: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/6.jpg)
What are actors?
Tuesday, 1 October 13
![Page 7: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/7.jpg)
@bantonsson@bantonsson
What are actors?
• Isolated lightweight event-based processes• Share nothing• Communicate through async messages• Each actor has a mailbox (message queue)• Location transparent (distributable)• Supervision-based failure management
7
Tuesday, 1 October 13
![Page 8: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/8.jpg)
@bantonsson@bantonsson
What is an actor good for?
• An island of sanity in a sea of concurrency• Everything inside the actor is sequential– Processes one message at a time
• Very lightweight– Create millions– Create short lived
• Inherently concurrent
8
Tuesday, 1 October 13
![Page 9: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/9.jpg)
@bantonsson@bantonsson
Actors compared to Objects
• Think of an Actor as an Object• You can't peek inside it• You don't call methods– You send messages (asynchronously)
• You don't get return values– You receive messages (asynchronously)
• The internal state is thread safe
9
Tuesday, 1 October 13
![Page 10: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/10.jpg)
Why should I care?
Tuesday, 1 October 13
![Page 11: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/11.jpg)
The world is multicore!
Tuesday, 1 October 13
![Page 12: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/12.jpg)
@bantonsson@bantonsson12
Amdahl’s Law
Tuesday, 1 October 13
![Page 13: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/13.jpg)
@bantonsson@bantonsson
So what's the catch?
• Really no catch• A different programming paradigm• All about tradeoffs– Some things are easier some harder
• Think different
13
Tuesday, 1 October 13
![Page 14: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/14.jpg)
Getting into the flow
Tuesday, 1 October 13
![Page 15: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/15.jpg)
@bantonsson@bantonsson
Getting into the flow
• Why do you need flow control?• How do you control the flow?• Do you really need all messages?
15
Tuesday, 1 October 13
![Page 16: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/16.jpg)
@bantonsson@bantonsson
Why do you need flow control?
• Function calls are blocking• Message sends are asynchronous• Possible problems– Produce jobs too fast– Many jobs need much CPU and/or Memory– External resources have limits– Unpredictable job patterns
16
Tuesday, 1 October 13
![Page 17: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/17.jpg)
@bantonsson@bantonsson
Why do you need flow control?
• Free flow of messages can lead to– Blocked from external resource– Actor mailbox backup– Slow system– Out of Memory
17
Tuesday, 1 October 13
![Page 18: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/18.jpg)
@bantonsson@bantonsson
How do you control the flow?
• Push with rate limiting– A fixed number of jobs per time unit
• Push with acknowledgment– A fixed number of jobs can be in progress– New jobs are started a"er old jobs finish
• Pull– New jobs are pulled as old are completed
18
Tuesday, 1 October 13
![Page 19: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/19.jpg)
@bantonsson@bantonsson
Push with rate limiting
• A timer sends ticks at fixed intervals• On every tick the master gets new tokens• When there are no tokens, jobs get queued• When there are tokens, start queued jobs
19
Tuesday, 1 October 13
![Page 20: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/20.jpg)
@bantonsson@bantonsson20
Worker
Master [0]
Queue [0]
TimerWorker
1. Work
Tuesday, 1 October 13
![Page 21: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/21.jpg)
@bantonsson@bantonsson21
Worker
Master [0]
Queue [1]
TimerWorker
1. Work 2. Enqueue
Tuesday, 1 October 13
![Page 22: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/22.jpg)
@bantonsson@bantonsson22
Worker
Master [5]
Queue [1]
TimerWorker
1. Work 2. Enqueue
3. Tick
Tuesday, 1 October 13
![Page 23: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/23.jpg)
@bantonsson@bantonsson23
Worker
Master [4]
Queue [0]
TimerWorker
1. Work 2. Enqueue
4. Dequeue
3. Tick
Tuesday, 1 October 13
![Page 24: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/24.jpg)
@bantonsson@bantonsson24
Worker
Master [4]
Queue [0]
TimerWorker
1. Work 2. Enqueue
4. Dequeue
3. Tick 5. Work
Tuesday, 1 October 13
![Page 25: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/25.jpg)
@bantonsson@bantonsson
Push with acknowledgement
• A fixed number of jobs are started• Wait for ACK before starting more jobs• Jobs that can't be started are queued• When ACK arrives start queued job• To keep workers busy, send more than one
job per worker– Use a high water mark to stop sending and a low
water mark to start sending
25
Tuesday, 1 October 13
![Page 26: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/26.jpg)
@bantonsson@bantonsson26
Worker
Master [0]
Queue [0]
Worker
1. Work
Tuesday, 1 October 13
![Page 27: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/27.jpg)
@bantonsson@bantonsson27
Worker
Master [0]
Queue [1]
Worker
1. Work 2. Enqueue
Tuesday, 1 October 13
![Page 28: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/28.jpg)
@bantonsson@bantonsson28
Worker
Master [1]
Queue [1]
Worker
1. Work 2. Enqueue
3. Ack
Tuesday, 1 October 13
![Page 29: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/29.jpg)
@bantonsson@bantonsson29
Worker
Master [0]
Queue [0]
Worker
1. Work 2. Enqueue
4. Dequeue3. Ack
Tuesday, 1 October 13
![Page 30: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/30.jpg)
@bantonsson@bantonsson30
Worker
Master [0]
Queue [0]
Worker
1. Work 2. Enqueue
4. Dequeue
5. Work3. Ack
Tuesday, 1 October 13
![Page 31: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/31.jpg)
@bantonsson@bantonsson31
Worker
Master [1]
Queue [0]
Worker
1. Work 2. Enqueue
4. Dequeue
5. Work
6. Ack
3. Ack
Tuesday, 1 October 13
![Page 32: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/32.jpg)
@bantonsson@bantonsson
Pull
• Incoming jobs are queued• Workers ask for jobs• Jobs are handed out when available• Workers don't do active polling• Can lead to lag if jobs are small compared to
cost of getting a new job– Use batching to counteract lag
32
Tuesday, 1 October 13
![Page 33: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/33.jpg)
@bantonsson@bantonsson33
Worker
Master
Queue [0]
Worker
1. Work
Tuesday, 1 October 13
![Page 34: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/34.jpg)
@bantonsson@bantonsson34
Worker
Master
Queue [1]
Worker
1. Work 2. Enqueue
Tuesday, 1 October 13
![Page 35: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/35.jpg)
@bantonsson@bantonsson35
Worker
Master
Queue [1]
Worker
1. Work 2. Enqueue
3. Work?
Tuesday, 1 October 13
![Page 36: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/36.jpg)
@bantonsson@bantonsson36
Worker
Master
Queue [0]
Worker
1. Work 2. Enqueue
4. Dequeue
3. Work?
Tuesday, 1 October 13
![Page 37: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/37.jpg)
@bantonsson@bantonsson37
Worker
Master
Queue [0]
Worker
1. Work 2. Enqueue
4. Dequeue
5. Work
3. Work?
Tuesday, 1 October 13
![Page 38: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/38.jpg)
@bantonsson@bantonsson
Do you really need all messages?
• Group messages together– Batching
• Discard/Aggregate messages– Scrubbing
38
Tuesday, 1 October 13
![Page 39: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/39.jpg)
@bantonsson@bantonsson
Batching
• Collect a number of messages before sending/processing them– A predefined number of messages or time
• Useful for things like– Write behind– Database bulk insert/update– Heavyweight operations e.g. GUI rendering
39
Tuesday, 1 October 13
![Page 40: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/40.jpg)
@bantonsson@bantonsson
Scrubbing
• Discard or aggregate some messages– Predefined number of messages or time
• Useful for things like– Financial market data– Statistics
40
Tuesday, 1 October 13
![Page 41: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/41.jpg)
Getting your message across
Tuesday, 1 October 13
![Page 42: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/42.jpg)
@bantonsson@bantonsson
Getting your message across
• When is a message delivered?• The fallacy of guaranteed delivery• What Akka guarantees• Reliable messaging
42
Tuesday, 1 October 13
![Page 43: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/43.jpg)
@bantonsson@bantonsson
When is a message delivered?
• Function calls block until done• Message sends return immediately• Which is the right point?– Sent/Received Network?– Enqueued/Dequeued Mailbox?– Processed by Actor?
• Do ACKing at the business level
43
Tuesday, 1 October 13
![Page 44: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/44.jpg)
@bantonsson@bantonsson
Guaranteed delivery
• From Enterprise Integration Patterns• Messaging system uses built-in store to
persist • ACK everywhere– Producer to sender– Sender to receiver– Receiver to consumer
44
Tuesday, 1 October 13
![Page 45: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/45.jpg)
@bantonsson@bantonsson
Lots of ACKs. What if I just...
• Use Durable Mailboxes?– When is the message in the mailbox?– No guarantees that it ever got there– Still have to ACK to be certain
45
Tuesday, 1 October 13
![Page 46: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/46.jpg)
@bantonsson@bantonsson
Lots of ACKs. What if I just...
• Use an External Durable Message Queue– A SPOF/Bottleneck?– When is the message in the message queue?– The queue does ACKing internally– No guarantees that it ever gets out– Still have to ACK to be certain
46
Tuesday, 1 October 13
![Page 47: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/47.jpg)
@bantonsson@bantonsson
Guaranteed delivery doesn't exist
• Things break– Persistent store crashes– Network fails– Server goes down
• Design for failure and resilience• Do ACKing at the business level
47
Tuesday, 1 October 13
![Page 48: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/48.jpg)
@bantonsson@bantonsson
What Akka guarantees
• At most once delivery– Message is only delivered once, if at all– The weakest guarantee
• Ordered per actor sender-receiver pair– Actor A sends messages to actor B– If the messages are received by actor B,
it will be in the order as sent by actor A
48
Tuesday, 1 October 13
![Page 49: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/49.jpg)
@bantonsson@bantonsson
Other delivery guarantees
• At least once– Message will eventually be delivered– Can happen multiple times
• Exactly once– Message will eventually be delivered– Will only happen once
• Have to add these yourself– They involve ACKing ;)
49
Tuesday, 1 October 13
![Page 50: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/50.jpg)
@bantonsson@bantonsson
Reliable Messaging: At least once
• Send with acknowledge– Keep sending until you get an ACK
• Receive with re-request– When missing a message request it– Needs unique sequence numbers
• Requires– Message store at sender (available/redundant)
50
Tuesday, 1 October 13
![Page 51: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/51.jpg)
@bantonsson@bantonsson51
SenderReceiver
Store
Tuesday, 1 October 13
![Page 52: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/52.jpg)
@bantonsson@bantonsson52
SenderReceiver
Store
1. Message
Tuesday, 1 October 13
![Page 53: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/53.jpg)
@bantonsson@bantonsson53
SenderReceiver
Store
2. Message
Tuesday, 1 October 13
![Page 54: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/54.jpg)
@bantonsson@bantonsson54
SenderReceiver3. Ack
Store
2. Message
Tuesday, 1 October 13
![Page 55: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/55.jpg)
@bantonsson@bantonsson55
SenderReceiver3. Ack
Store
4. Ack
2. Message
Tuesday, 1 October 13
![Page 56: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/56.jpg)
@bantonsson@bantonsson
Reliable Messaging: At least once
• Use a pipe of actors before ACKing• Keep pipe free of side effects– Same message might come several times
• ACK should be done at the business level
56
Tuesday, 1 October 13
![Page 57: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/57.jpg)
@bantonsson@bantonsson57
Sender
CheckInventory
Authenticate
ReceiverStore
Tuesday, 1 October 13
![Page 58: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/58.jpg)
@bantonsson@bantonsson58
Sender
CheckInventory
Authenticate
ReceiverStore
1. Message
Tuesday, 1 October 13
![Page 59: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/59.jpg)
@bantonsson@bantonsson59
Sender
CheckInventory
Authenticate
Receiver
2. Message
Store
Tuesday, 1 October 13
![Page 60: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/60.jpg)
@bantonsson@bantonsson60
Sender
CheckInventory
Authenticate
Receiver
2. Message
3. Message'
Store
Tuesday, 1 October 13
![Page 61: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/61.jpg)
@bantonsson@bantonsson61
Sender
CheckInventory
Authenticate
Receiver
4. Message''
2. Message
3. Message'
Store
Tuesday, 1 October 13
![Page 62: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/62.jpg)
@bantonsson@bantonsson62
Sender
CheckInventory
Authenticate
Receiver
4. Message''
2. Message
3. Message'
5. Ack
Store
Tuesday, 1 October 13
![Page 63: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/63.jpg)
@bantonsson@bantonsson63
Sender
CheckInventory
Authenticate
Receiver
4. Message''
2. Message
3. Message'
5. Ack
Store
6. Ack
Tuesday, 1 October 13
![Page 64: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/64.jpg)
@bantonsson@bantonsson
Receive with re-request
• When missing a message request it• Requires– Uniquely identifiable sequence– Message store at sender (available/redundant)
64
Tuesday, 1 October 13
![Page 65: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/65.jpg)
@bantonsson@bantonsson65
SenderReceiver
Store
Tuesday, 1 October 13
![Page 66: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/66.jpg)
@bantonsson@bantonsson66
SenderReceiver
Store
1. Message
Tuesday, 1 October 13
![Page 67: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/67.jpg)
@bantonsson@bantonsson67
SenderReceiver
Store
2. Message
Tuesday, 1 October 13
![Page 68: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/68.jpg)
@bantonsson@bantonsson68
SenderReceiver
Store
3. Message'
Tuesday, 1 October 13
![Page 69: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/69.jpg)
@bantonsson@bantonsson69
SenderReceiver
Store
4. Message'
Tuesday, 1 October 13
![Page 70: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/70.jpg)
@bantonsson@bantonsson70
SenderReceiver5. Request
Store
4. Message'
Tuesday, 1 October 13
![Page 71: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/71.jpg)
@bantonsson@bantonsson71
SenderReceiver
Store
6. Message
Tuesday, 1 October 13
![Page 72: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/72.jpg)
@bantonsson@bantonsson72
SenderReceiver
Store
6. Message
7. Message
Tuesday, 1 October 13
![Page 73: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/73.jpg)
@bantonsson@bantonsson73
SenderReceiver
Store
8. Message'
Tuesday, 1 October 13
![Page 74: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/74.jpg)
@bantonsson@bantonsson74
SenderReceiver
Store
8. Message'
9. Message'
Tuesday, 1 October 13
![Page 75: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/75.jpg)
Tying it all together
Tuesday, 1 October 13
![Page 76: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/76.jpg)
@bantonsson@bantonsson
Tying it all together
• Distributed Workers Example– Front Ends receive requests– Master receives work from Front Ends– Workers pull work from Master
• Available as a Typesafe Activator template– Zero configuration setup– Code and tutorial
76
Tuesday, 1 October 13
![Page 77: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/77.jpg)
@bantonsson@bantonsson77
Worker
Master
Worker
Worker
Worker
Frontend
Frontend
Tuesday, 1 October 13
![Page 78: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/78.jpg)
@bantonsson@bantonsson
Tying it all together
• Further Goals– Elastic addition/removal of front end nodes– Elastic addition/removal of workers– Thousands of workers– Jobs should not be lost
78
Tuesday, 1 October 13
![Page 79: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/79.jpg)
@bantonsson@bantonsson79
Master
Worker
Frontend
WorkExecutor
Tuesday, 1 October 13
![Page 80: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/80.jpg)
@bantonsson@bantonsson80
Master
Worker
Frontend
WorkExecutor
RegisterWorker
Tuesday, 1 October 13
![Page 81: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/81.jpg)
@bantonsson@bantonsson81
Master
Worker
Frontend
1. Work
WorkExecutor
Tuesday, 1 October 13
![Page 82: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/82.jpg)
@bantonsson@bantonsson82
Master
Worker
Frontend
1. Work
2. Work
WorkExecutor
Tuesday, 1 October 13
![Page 83: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/83.jpg)
@bantonsson@bantonsson83
Master
Worker
Frontend
1. Work
2. Work
3. Ack
WorkExecutor
Tuesday, 1 October 13
![Page 84: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/84.jpg)
@bantonsson@bantonsson84
Master
Worker
Frontend
1. Work
2. Work
3. Ack
4. OK
WorkExecutor
Tuesday, 1 October 13
![Page 85: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/85.jpg)
@bantonsson@bantonsson85
Master
Worker
Frontend
1. Work
2. Work
3. Ack
4. OK
5. WorkIsReady
WorkExecutor
Tuesday, 1 October 13
![Page 86: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/86.jpg)
@bantonsson@bantonsson86
Master
Worker
Frontend
1. Work
2. Work
3. Ack
4. OK
5. WorkIsReady
6. WorkerRequestWork
WorkExecutor
Tuesday, 1 October 13
![Page 87: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/87.jpg)
@bantonsson@bantonsson87
Master
Worker
Frontend
1. Work
2. Work
3. Ack
4. OK
5. WorkIsReady
6. WorkerRequestWork7. Work
WorkExecutor
Tuesday, 1 October 13
![Page 88: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/88.jpg)
@bantonsson@bantonsson88
Master
Worker
Frontend
1. Work
2. Work
3. Ack
4. OK
5. WorkIsReady
6. WorkerRequestWork7. Work
WorkExecutor
8. Work
Tuesday, 1 October 13
![Page 89: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/89.jpg)
@bantonsson@bantonsson89
Master
Worker
Frontend
WorkExecutor
Tuesday, 1 October 13
![Page 90: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/90.jpg)
@bantonsson@bantonsson90
Master
Worker
Frontend
WorkExecutor
9. WorkComplete
Tuesday, 1 October 13
![Page 91: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/91.jpg)
@bantonsson@bantonsson91
Master
Worker
Frontend
WorkExecutor
9. WorkComplete
10. WorkIsDone
Tuesday, 1 October 13
![Page 92: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/92.jpg)
@bantonsson@bantonsson92
Master
Worker
Frontend
WorkExecutor
9. WorkComplete
10. WorkIsDone
11. Ack
Tuesday, 1 October 13
![Page 93: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/93.jpg)
@bantonsson@bantonsson
Cluster Technologies/Patterns
• Distributed Pub/Sub Mediator– Publish and Subscribe to message flows
• Cluster Singleton– HA singleton actor instance within the cluster
• Cluster Client– Let other systems connect to the cluster
93
Tuesday, 1 October 13
![Page 94: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/94.jpg)
@bantonsson@bantonsson
DistributedPubSubMediator94
Frontend Master
Mediator Mediator
Tuesday, 1 October 13
![Page 95: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/95.jpg)
@bantonsson@bantonsson
DistributedPubSubMediator95
Frontend Master
Mediator Mediator
Put
Tuesday, 1 October 13
![Page 96: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/96.jpg)
@bantonsson@bantonsson
DistributedPubSubMediator96
Frontend Master
Mediator Mediator
Send
Tuesday, 1 October 13
![Page 97: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/97.jpg)
@bantonsson@bantonsson
DistributedPubSubMediator97
Frontend Master
Mediator Mediator
Send
Tuesday, 1 October 13
![Page 98: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/98.jpg)
@bantonsson@bantonsson
ClusterSingleton98
ClusterSingletonManager
ClusterSingletonManager
MasterMaster(Standby)
Tuesday, 1 October 13
![Page 99: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/99.jpg)
@bantonsson@bantonsson
ClusterSingleton99
ClusterSingletonManager
ClusterSingletonManager
MasterMaster(Standby)
Tuesday, 1 October 13
![Page 100: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/100.jpg)
@bantonsson@bantonsson
ClusterSingleton100
ClusterSingletonManager
ClusterSingletonManager
Master Master
Tuesday, 1 October 13
![Page 101: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/101.jpg)
@bantonsson@bantonsson
ClusterClient & ClusterSingleton101
Master
Mediator
Mediator
Receptionist
Master(Standby)
Receptionist
ClusterClient
ClusterClient
Worker
Worker
Tuesday, 1 October 13
![Page 102: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/102.jpg)
@bantonsson@bantonsson102
Master
Mediator
Mediator
Receptionist
Master(Standby)
Receptionist
ClusterClient
ClusterClient
Worker
Worker
ClusterClient
Worker
Worker
Frontend
Frontend
Tuesday, 1 October 13
![Page 103: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/103.jpg)
Resources
Tuesday, 1 October 13
![Page 104: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/104.jpg)
@bantonsson@bantonsson
Resources: Blog Posts
• Push with rate limiting– Kaspar Fischer
http://letitcrash.com/post/28901663062/throttling-messages-in-akka-2
• Pull– Derek Wyatt
http://letitcrash.com/post/29044669086/balancing-workload-across-nodes-with-akka-2
– Michael Pollmeierhttp://www.michaelpollmeier.com/akka-work-pulling-pattern-to-throttle-work/
104
Tuesday, 1 October 13
![Page 105: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/105.jpg)
@bantonsson@bantonsson
Resources: Typesafe Activator
• http://typesafe.com/platform/getstarted
105
Tuesday, 1 October 13
![Page 106: Real World Akka Actor Recipes JavaOne 2013](https://reader033.vdocuments.mx/reader033/viewer/2022060108/554f577cb4c905423f8b56a1/html5/thumbnails/106.jpg)
@bantonsson@bantonsson
Resources: Coursera Course
• Principles of Reactive Programming byMartin Odersky, Erik Meijer and Roland Kuhn– Starts 4th of November 2013– 7 weeks– Workload: 5-7 hours a week– Free as in free beer
• https://www.coursera.org/course/reactive
106
Tuesday, 1 October 13