Cover image for Effective Akka

Book description

Avoid common mistakes when building distributed, asynchronous, high-performance software with the Akka toolkit and runtime. With this concise guide, author Jamie Allen provides a collection of best practices based on several years of using the actor model. The book also includes examples of actor application types and two primary patterns of actor usage, the Extra Pattern and Cameo Pattern.

Table of Contents

  1. Special Upgrade Offer
  2. Preface
    1. Who This Book Is For
    2. What Problems Are We Solving with Akka?
      1. Distributed
      2. Asynchronous
      3. High Performance
    3. Reactive Applications
    4. Use Case for This Book: Banking Service for Account Data
    5. Conventions Used in This Book
    6. Using Code Examples
    7. Safari® Books Online
    8. How to Contact Us
    9. Acknowledgments
  3. 1. Actor Application Types
    1. Domain-driven
      1. Domain-driven Messages Are “Facts”
    2. Work Distribution
      1. Routers and Routees
        1. Random
        2. Round robin
        3. Smallest mailbox
        4. Broadcast
        5. ScatterGatherFirstCompletedOf
        6. Consistent hash routing
      2. BalancingDispatcher Will Be Deprecated Soon!
      3. Work Distribution Messages Are “Commands”
  4. 2. Patterns of Actor Usage
    1. The Extra Pattern
      1. The Problem
      2. Avoiding Ask
      3. Capturing Context
      4. Sending Yourself a Timeout Message
        1. Why not use a promise?
        2. How to test this logic
    2. The Cameo Pattern
      1. The Companion Object Factory Method
      2. How to Test This Logic
  5. 3. Best Practices
    1. Actors Should Do Only One Thing
      1. Single Responsibility Principle
      2. Create Specific Supervisors
      3. Keep the Error Kernel Simple
      4. Failure Zones
    2. Avoid Blocking
      1. Futures Delegation Example
        1. Java futures are blocking!
      2. Pre-defining Parallel Futures
      3. Parallel Futures with the zip() Method
      4. Sequential Futures
      5. Callbacks versus Monadic Handling
      6. Futures and ExecutionContext
      7. Push, Don’t Pull
      8. When You Must Block
      9. Managed Blocking in Scala
    3. Avoid Premature Optimization
      1. Start Simple
        1. Deterministic
        2. Declarative
        3. Immutable
        4. Functional
      2. Layer in Complexity via Indeterminism
      3. Optimize with Mutability
        1. Add mutability with compare and swap (CAS)
        2. Compose CAS with Software Transactional Memory
        3. Add locks as a last resort
      4. Prepare for Race Conditions
        1. Avoid coding in a way where timing matters
        2. Tell, don’t ask
    4. Be Explicit
      1. Name Actors and ActorSystem Instances
      2. Create Specialized Messages
      3. Create Specialized Exceptions
      4. Beware the “Thundering Herd”
        1. Dampen message overload
        2. Use circuit breakers for failure overload
    5. Don’t Expose Actors
      1. Avoid Using this
      2. The Companion Object Factory Method
      3. Never Use Direct References
      4. Don’t Close Over Variables
      5. Use Immutable Messages with Immutable Data
    6. Help Yourself in Production
      1. Make Debugging Easier
      2. Add Metrics
      3. Externalize Business Logic
      4. Use Semantically Useful Logging
      5. Aggregate Your Logs with a Tool Like Flume
      6. Use Unique IDs for Messages
    7. Tune Akka Applications with the Typesafe Console
      1. Fixing Starvation
        1. How do you fix it?
        2. Does PinnedDispatcher help?
        3. Failure zones
        4. Routers
      2. Sizing Dispatchers
      3. The Parallelism-Factor Setting
      4. Actor Mailbox Size
      5. Throughput Setting
      6. Edge Cases
  6. About the Author
  7. Colophon
  8. Special Upgrade Offer
  9. Copyright