Does InstanceCount=1 in ServiceFabric mean 'at least one instance' or 'no more than one instance'? From the documentation I've seen it's unclear and I have a scenario where I want at most one instance of my application running at any one time.
Does InstanceCount=1 in ServiceFabric mean 'at least one instance' or 'no more than one instance'?
120 Views Asked by Rob Bell AtThere are 2 best solutions below
On
When setting the instance count to 1, it means that eventually the service would have only 1 instance, but there may be cases, especially during service startup that you will have more than 1 instance. Therefore its not 'no more than one instance on any given time' Personally I have seen cases where a service would startup and it was running on all nodes for a few seconds until the cluster honored the instance count and placement constraints and eventually reduced the instance count as configured. If you are trying to use this functionality to implement a business logic that has to run at most once on any given time, you should implement a distributed lock in your logic as well (e.g. use Azure blob storage lease).
According to Github by tomvcassidy Instance Count=1 in Service Fabric means at least one instance
When
InstanceCountis set to 1, it means that exactly one instance of the service will be created and running at any given moment. In order to keep the desired instance count of 1 if the instance fails or removed, Service Fabric will automatically create a new instance.If you want to ensure that at most one instance of your application is running at any one time, you can set the
InstanceCountproperty to 1.This configuration ensures that only one instance of the service is running, and if that instance fails or is removed, Service Fabric will automatically create a new instance to maintain the desired count of 1.