Skip to content

Instantly share code, notes, and snippets.

@jamie-allen
Created July 3, 2013 18:29
Show Gist options
  • Save jamie-allen/5921362 to your computer and use it in GitHub Desktop.
Save jamie-allen/5921362 to your computer and use it in GitHub Desktop.
80 pages in pre-production length
Preface
Part I. Actor Application Types
1. Domain-Driven
Domain-driven messages are “facts”
2. Work Distribution
Routers and routees
Random
Round Robin
Smallest Mailbox
Broadcast
ScatterGatherFirstCompletedOf
Consistent Hash Routing
BalancingDispatcher will be deprecated soon!
Work distribution messages are “commands”
Part II. Patterns of Actor Usage
3. The Extra Pattern
The problem
Avoiding ask
Capturing context
Sending yourself a timeout message
Why not use a Promise?
How to test this logic
4. The Cameo Pattern
The Cameo Companion Object Factory Method
How to test this logic
Part III. Best Practices
5. Actors Should Do Only One Thing
Single Responsibility Principle
Create specific supervisors
Keep the error kernel simple
Failure zones
6. Avoid Blocking
Futures delegation example
Java futures are blocking!
Pre-defining parallel futures
Parallel futures with the zip method
Sequential futures
Callbacks versus monadic handling
Futures and ExecutionContext
Push, don’t pull
When you must block
Managed Blocking in Scala
7. Avoid Premature Optimization
Start simple
Deterministic
Declarative
Immutable
Functional
Layer in complexity via indeterminism
Optimize with mutability
Add mutability with Compare and Swap (CAS)
Compose CAS with Software Transactional Memory
Add locks as a last resort
Prepare for race conditions
Avoid coding in a way where timing matters
Tell, don’t ask
8. Be Explicit
Name Actors and ActorSystem instances Create specialized messages
Create specialized exceptions
Beware the “thundering herd”
Dampen message overload
Use circuit breakers for failure overload
9. Don’t Expose Actors
Avoid using “this”
The Companion Object Factory Method
Never use direct references
Don’t close over variables
Use immutable messages with immutable data
10. Help Yourself in Production
Make debugging easier
Add Metrics
Externalize business logic
Use semantically-useful logging
Aggregate your logs with a tool like Flume
Use unique IDs for messages
11. Tune Akka Applications with the Typesafe Console
Fixing Starvation
How do you fix it?
Does PinnedDispatcher help?
Failure zones
Routers
Sizing dispatchers
The Parallelism-Factor setting
Actor Mailbox Size
Throughput Setting
Edge Cases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment