Poul K. Sørensen
Poul K. Sørensen

Reputation: 17540

How to run something on each node in service fabric

In a service fabric application, using Actors or Services - what would the design be if you wanted to make sure that your block of code would be run on each node.

My first idea would be that it had to be a Service with instance count set to -1, but also in cases that you had set to to 3 instances. How would you make a design where the service ensured that it ran some operation on each instance.

My own idea would be having a Actor with state controlling the operations that need to run, and it would itterate over services using serviceProxy to call methods on each instance - but thats just a naive idea for which I dont know if its possible or if it is the proper way to do so?

Upvotes: 0

Views: 588

Answers (1)

LoekD
LoekD

Reputation: 11470

Some background info

Only Stateless services can be given a -1 for instance count. You can't use a ServiceProxy to target a specific instance.

Stateful services are deployed using 1 or more partitions (data shards). Partition count is configured in advance, as part of the service deployment and can't be changed automatically. For instance if your cluster is scaled out, partitions aren't added automatically.

Autonomous workers

Maybe you can invert the control flow by running Stateless services (on all nodes) and have them query a 'repository' for work items. The repository could be a Stateful service, that stores work items in a Queue.

This way, adding more instances (scaling out the cluster) increases throughput without code modification. The stateless service instances become autonomous workers. (opposed to an intelligent orchestrator Actor)

Upvotes: 1

Related Questions