Bulkheading with Dispatchers
Adding fault tolerance to your Akka application
In the previous post I talked about what dispatchers and their types. I also mentioned that dispatchers can be used to add bulkheading to your application. In this post I’ll show a minimal example of how we can add a bulkhead using dispatchers.
previous post:
Let’s start by creating a RogueActor. This actor will simulate hogging the CPU by sleeping for a long time on receiving a request.
Next we’ll add a dispatcher with fewer threads in addition to the one we already have. Update your reference.conf to the following
I’ve set the rogue-dispatcher to just 1 thread so that it’ll block other messages from being processed.
Next, update SupervisorActor to the following
What I’ve done is to make GreetingsActor and RogueActor share the same dispatcher. This way, GreetingsActor will block because RogueActor is using up all the threads. Another thing is to pass the RogueRequest to the RogueActor
Finally, update Main.scala to send a few messages to RogueActor
When you run this app, you’ll see the futures timing out. This is because the RogueRequest is taking up the CPU. To mitigate this, we’ll move GreetingsActor to another dispatcher.
Run the app again and you’ll see the proper output. That’s how you add bulkheads with dispatchers.