Example: Cluster Client
The standalone example’s actors, unchanged, in a cluster: three cluster nodes, a satellite that hosts the actors, and a client that asks through the cluster. The client runs the same scenario; only its host changed.
The roles
| Process | Role | What it starts |
|---|---|---|
cluster-0..2 |
node |
Node.startGuardedClusterNodeWith system self guard seeds |
satellite |
satellite |
Sat.startGuardedSatellite system self guard seeds hostings |
client |
client |
Ast.startGuardedAsteroid system self guard seeds |
One program does all three; DEMO_ROLE picks (src/Demo/Roles.ai):
roleRun :: DemoSettings -> ActorSystem -> Int
roleRun s system = case settingsRole s of
RoleStandalone -> asked s (localClient system s)
RoleClient -> asked s (remoteClient system s)
RoleNode -> served s (Node.startGuardedClusterNodeWith system (settingsSelf s) (settingsGuard s) (settingsSeeds s))
RoleSatellite -> served s (Sat.startGuardedSatellite system (settingsSelf s) (settingsGuard s) (settingsSeeds s) (hostingsOf s))
RoleHybrid -> served s (startHost system (guardedBy (settingsGuard s) (hostConfig Hybrid (settingsSelf s) (settingsSeeds s) (hostingsOf s))))
The client
The client is an asteroid. Its ActorClient is the one type the scenario takes, so the scenario is the standalone
one:
remoteClient :: ActorSystem -> DemoSettings -> Either Fault ActorClient
remoteClient system s = case Ast.startGuardedAsteroid system (settingsSelf s) (settingsGuard s) (settingsSeeds s) of
Right asteroid -> Right (RemoteClient asteroid)
Left f -> Left f
A cluster takes a moment to form, so the scenario first asks until an answer comes back (every half second, for up to 30 seconds), then runs the exchanges.
What happens to one ask
- The client sends the work for
account/aliceto a cluster node, through its outbox: the work is kept until the node acknowledges it, and sent to another node meanwhile if it does not. - The node looks the route up in its route table. Unknown, it has the least loaded satellite that can run
account/{id}make the actor. - The satellite makes Alice’s actor, hands it the payload, and sends the answer back as a forwarded response.
- The node forwards the answer to the client.
The route table is a CRDT shared by gossip, so every cluster node knows where Alice’s actor is, whichever node the next ask reaches.
Run it
cd MLambda.Actor.Demo
docker compose -f compose.cluster.yml up --build --abort-on-container-exit --exit-code-from client
Every connection of the cluster is sealed: identities (fortress-issue) gives each process its identity from the
cluster’s CA before any starts. compose.fortress.yml is the same cluster with a stranger beside it, whose identity
another CA issued; it is not admitted, and every frame between the others is
encrypted and authenticated.
Next
Nodes that route and host at once: Hybrid Service.