Coordinator Avoidance Shard Allocation Strategy

CI

Motivation

We faced response time (latency) spikes during a rolling update in some specific situations with Akka Cluster Sharding. This challenge is because we lose the ShardCoordinator and ShardHome cache simultaneously. To address this challenge, we've implemented a custom shard allocation strategy (called Coordinator Avoidance Shard Allocation Strategy). This strategy avoids allocating Shards to the oldest node hosting the ShardCoordinator. This strategy can reduce such latency spikes if we ensure that all nodes cached all ShardHomes before shutting the oldest node. This strategy reduces about 80% latency at stopping the oldest node. The evaluation and the first design are available here.

Getting Started

You have to add a dependency into your project to use this library. Add the following lines to your build.sbt file:

Stable Release (Not Available)
Maven Central
Replace "X.Y.Z" with the actual version you want to use.

libraryDependencies += "com.lerna-stack" %% "akka-coordinator-avoidance-shard-allocation-strategy" % "X.Y.Z"

Unstable Release (SNAPSHOT)
Sonatype Nexus (Snapshots)
Replace "X.Y.Z" with the actual version you want to use.

// You have to refer to Sonatype if you use a snapshot version.
resolvers += Resolver.sonatypeRepo("snapshots") 

libraryDependencies += "com.lerna-stack" %% "akka-coordinator-avoidance-shard-allocation-strategy" % "X.Y.Z-SNAPSHOT"

Using with Akka Cluster Sharding (Classic)

Since this library depends on Akka Cluster Sharding as a provided scope, you have to add Akka Cluster Sharding (Classic) into your project like below explicitly.

libraryDependencies += "com.typesafe.akka" %% "akka-cluster-sharding" % "2.6.17"

Note that you can choose another version of Akka Cluster Sharding. For more details, please see Supported Akka versions.

You can specify this strategy using ClusterSharding.start method. An example is available here.

We select default setting values to be effective and safe in most cases. You can override the settings defined at reference.conf.

Using with Akka Cluster Sharding (Typed)

Since this library depends on Akka Cluster Sharding as a provided scope, you have to add Akka Cluster Sharding (Typed) into your project like below explicitly.

libraryDependencies += "com.typesafe.akka" %% "akka-cluster-sharding-typed" % "2.6.17"

Note that you can choose another version of Akka Cluster Sharding. For more details, please see Supported Akka versions.

You can specify this strategy using Entity.withAllocationStrategy method. An example is available here

We select default setting values to be effective and safe in most cases. You can override the settings defined at reference.conf.

Supported versions

Supported Akka versions

We recommend using Akka 2.6.16 or above since we've tested this library with Akka 2.6.16. However, this library can work with Akka 2.6.0 or above in theory.

Supported Scala versions

This library supports Scala 2.13 only now.

Supported JDK versions

This library supports JDK8 and JDK11.

Changelog

You can see all the notable changes in CHANGELOG.

For Contributors

CONTRIBUTING might help us.

For Maintainers

RELEASING describes how to release a new version.

License

akka-coordinator-avoidance-shard-allocation-strategy is released under the terms of the Apache License Version 2.0.



* The names of the companies and products described in this site are trademarks or registered trademarks of the respective companies.
* Akka is a trademark of Lightbend, Inc.

© 2021 TIS Inc.