-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add Member Roles
doc
#5742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add Member Roles
doc
#5742
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
a81c258
Add `Node Roles` doc
eaba 4563c2c
Merge branch 'dev' into cluster_roles
eaba 5de627d
Update documentation
eaba 210ae39
Fixed lint errors
eaba d7de54a
Merge branch 'dev' into cluster_roles
eaba 8529d77
Added diagram image
eaba 876a5b4
replaced cluster roles diagram with a simpler version
eaba 76ff75a
Added cluster config example for other cluster modules
eaba a2374d4
Add more detail on what the roles do
eaba 400bec0
Added more detail
eaba 66a4b6f
Merge branch 'dev' into cluster_roles
eaba 82a4380
Fix tabbing
eaba 6fee097
Attempt formating fix
eaba dbd5dd5
Moved `cluster-roles.png` to `cluster` folder under images
eaba aad9f44
* Fix heading with H2
eaba 854d723
Fix hard tabs
eaba a300b06
* created new image
eaba 3bc1939
Updated documentation
eaba ae9a01f
Merge branch 'dev' into cluster_roles
eaba fca18c5
Fix linting issues
eaba d16ea43
Fix linting issue
eaba c8ab363
Update cluster-overview.md
Aaronontheweb 43d8791
Update member-roles.md
Aaronontheweb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,317 @@ | ||
--- | ||
uid: member-roles | ||
title: Member Roles | ||
--- | ||
|
||
# Member Roles | ||
|
||
 | ||
|
||
A cluster can have multiple nodes(machines/servers/vms) with different capabilities. | ||
When you require an application to run on a node(machine/server/vm) with certain capabilities, roles helps you to distinguish the nodes so that application can be deployed on that node. | ||
Specifying cluster role(s) is a best practice; you don't want an application that requires less computational power running and consuming resources meant for a mission-critical and resource-intensive application. | ||
Even if you only have a single type of node in your cluster, you should still use roles for it so you can leverage this infrastructure as your cluster expands in the future; and they add zero overhead in any conceivable way. | ||
|
||
# How To Configure Cluster Role | ||
|
||
|
||
Below I will show you how the cluster above can be reproduced. I will create a five-nodes(ActorSystems - all having same name, though, but living on different machine/server/vm) cluster with different roles applied: | ||
|
||
**Node1**: All of my code that receives requests from users and push same to the cluster will be deployed here! | ||
|
||
```hocon | ||
akka | ||
{ | ||
cluster | ||
{ | ||
roles = ["web"] | ||
} | ||
} | ||
``` | ||
|
||
**Node2**: All of my code handling fraud detections will be deployed on this node | ||
|
||
```hocon | ||
akka | ||
{ | ||
cluster | ||
{ | ||
roles = ["fraud"] | ||
} | ||
} | ||
``` | ||
|
||
**Node3**: All me code that retrieves, stores data will be deployed on this node | ||
|
||
```hocon | ||
akka | ||
{ | ||
cluster | ||
{ | ||
roles = ["storage"] | ||
} | ||
} | ||
``` | ||
|
||
**Node4**: All my code that handles customer orders will be deployed on this node | ||
|
||
```hocon | ||
akka | ||
{ | ||
cluster | ||
{ | ||
roles = ["order"] | ||
} | ||
} | ||
``` | ||
|
||
**Node5**: All my code that handles customer billing will be deployed on this node | ||
|
||
```hocon | ||
akka | ||
{ | ||
cluster | ||
{ | ||
roles = ["billing"] | ||
} | ||
} | ||
``` | ||
|
||
Now that we have laid the foundation for what is to follow, Akka.Cluster is made of various ready-made extensions(or modules) you can deploy. | ||
I will show you how you can deploy them on any of the nodes. Apart from the Akka.Cluster modules, if you just want to use the Akka.Cluster core, I will show you how you can deploy your own actor to the cluster node with the required role: | ||
|
||
**Cluster Sharding**: Sharding be will deployed on the nodes with the `order` role, `node4` | ||
|
||
```hocon | ||
akka | ||
{ | ||
cluster | ||
{ | ||
roles = ["order"] | ||
sharding | ||
{ | ||
role = "order" | ||
} | ||
} | ||
} | ||
``` | ||
|
||
**Distributed Pub-Sub**: DistributedPubSub will be deployed on the nodes with the `web` role, `node1`. | ||
|
||
```hocon | ||
akka | ||
{ | ||
cluster | ||
{ | ||
roles = ["web"] | ||
pub-sub | ||
{ | ||
role = "web" | ||
} | ||
} | ||
} | ||
``` | ||
|
||
**Distributed Data**: DistributedData will be deployed on the node with the `storage` role, `node3`. | ||
|
||
```hocon | ||
akka | ||
{ | ||
cluster | ||
{ | ||
roles = ["storage"] | ||
distributed-data | ||
{ | ||
role = "storage" | ||
} | ||
} | ||
} | ||
``` | ||
|
||
**Cluster Singleton**: To avoid over charging a customer more than once, my code will be deployed with `ClusterSingleton` on the node with the `billing` role, `node5` | ||
|
||
```hocon | ||
akka | ||
{ | ||
cluster | ||
{ | ||
roles = ["billing"] | ||
singleton | ||
{ | ||
role = "billing" | ||
} | ||
} | ||
} | ||
``` | ||
|
||
I have one more node, `node2`, with nothing running in it. I will deploy my custom fraud detection code there, and the way to do that is: | ||
|
||
```csharp | ||
var selfMember = Cluster.Get(_actorSystem).SelfMember; | ||
if (selfMember.HasRole("fraud")) | ||
{ | ||
context.ActorOf(Billing.Prop(), "bill-gate"); | ||
} | ||
else | ||
{ | ||
//sleep, probably! | ||
} | ||
``` | ||
|
||
Using the Cluster `SelfMember`, I am checking if the current node has the `billing` role and if yes, create the `Billing` actor. | ||
|
||
## Cluster-Aware Router | ||
|
||
Cluster-Aware routers automate how actors are deployed on the cluster and also how messages are routed based on the role specified! Routers in Akka.NET can be either grouped or pooled and you can read up on them [Routers](https://getakka.net/articles/actors/routers.html) | ||
|
||
**Router Group**: I will create Cluster-Aware Router Group for all my applications above! | ||
|
||
```hocon | ||
akka | ||
{ | ||
actor | ||
{ | ||
provider = "Akka.Cluster.ClusterActorRefProvider, Akka.Cluster" | ||
deployment | ||
{ | ||
/webdispatcher | ||
{ | ||
router = consistent-hashing-group # routing strategy | ||
routees.paths = ["/user/web"] # path of routee on each node | ||
nr-of-instances = 3 # max number of total routees | ||
cluster | ||
{ | ||
enabled = on | ||
use-role = "web" | ||
} | ||
} | ||
/frauddispatcher | ||
{ | ||
router = consistent-hashing-group # routing strategy | ||
routees.paths = ["/user/fraud"] # path of routee on each node | ||
nr-of-instances = 3 # max number of total routees | ||
cluster | ||
{ | ||
enabled = on | ||
use-role = "fraud" | ||
} | ||
} | ||
/billingdispatcher | ||
{ | ||
router = consistent-hashing-group # routing strategy | ||
routees.paths = ["/user/billing"] # path of routee on each node | ||
nr-of-instances = 3 # max number of total routees | ||
cluster | ||
{ | ||
enabled = on | ||
use-role = "billing" | ||
} | ||
} | ||
/orderdispatcher | ||
{ | ||
router = consistent-hashing-group # routing strategy | ||
routees.paths = ["/user/order"] # path of routee on each node | ||
nr-of-instances = 3 # max number of total routees | ||
cluster | ||
{ | ||
enabled = on | ||
use-role = "order" | ||
} | ||
} | ||
/storagedispatcher | ||
{ | ||
router = consistent-hashing-group # routing strategy | ||
routees.paths = ["/user/storage"] # path of routee on each node | ||
nr-of-instances = 3 # max number of total routees | ||
cluster | ||
{ | ||
enabled = on | ||
use-role = "storage" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
```csharp | ||
var web = system.ActorOf<Web>("web"); | ||
var fraud = system.ActorOf<Fraud>("fraud"); | ||
var order = system.ActorOf<Order>("order"); | ||
var billing = system.ActorOf<Billing>("billing"); | ||
var storage = system.ActorOf<Storage>("storage"); | ||
|
||
var webRouter = system.ActorOf(Props.Empty.WithRouter(FromConfig.Instance),"webdispatcher"); | ||
var fraudRouter = system.ActorOf(Props.Empty.WithRouter(FromConfig.Instance),"frauddispatcher"); | ||
var orderRouter = system.ActorOf(Props.Empty.WithRouter(FromConfig.Instance),"orderdispatcher"); | ||
var billingRouter = system.ActorOf(Props.Empty.WithRouter(FromConfig.Instance),"billingispatcher"); | ||
var storageRouter = system.ActorOf(Props.Empty.WithRouter(FromConfig.Instance),"storagedispatcher"); | ||
``` | ||
|
||
**Router Pool**: I will create Cluster-Aware Router Pool for all my applications above! | ||
|
||
```hocon | ||
akka | ||
{ | ||
actor | ||
{ | ||
provider = "Akka.Cluster.ClusterActorRefProvider, Akka.Cluster" | ||
deployment | ||
{ | ||
/webdispatcher | ||
{ | ||
router = round-robin-pool # routing strategy | ||
max-nr-of-instances-per-node = 5 | ||
cluster | ||
{ | ||
enabled = on | ||
use-role = "web" | ||
} | ||
} | ||
/frauddispatcher | ||
{ | ||
router = round-robin-pool # routing strategy | ||
max-nr-of-instances-per-node = 5 | ||
cluster | ||
{ | ||
enabled = on | ||
use-role = "fraud" | ||
} | ||
} | ||
/billingdispatcher | ||
{ | ||
router = round-robin-pool # routing strategy | ||
max-nr-of-instances-per-node = 5 | ||
cluster | ||
{ | ||
enabled = on | ||
use-role = "billing" | ||
} | ||
} | ||
/orderdispatcher | ||
{ | ||
router = round-robin-pool # routing strategy | ||
max-nr-of-instances-per-node = 5 | ||
cluster | ||
{ | ||
enabled = on | ||
use-role = "order" | ||
} | ||
} | ||
/storagedispatcher | ||
{ | ||
router = round-robin-pool # routing strategy | ||
max-nr-of-instances-per-node = 5 | ||
cluster | ||
{ | ||
enabled = on | ||
use-role = "storage" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
```csharp | ||
var routerProps = Props.Empty.WithRouter(FromConfig.Instance); | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use
xref
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, should probably add a comment earlier in the actual literature of this page about cluster roles, rather than just slapping a link in the "additional resources" section - introduce the context of what a role is sooner while we're introducing other Akka.Cluster concepts.