问题
My stateless service receives tasks from Service Bus queue and processes it. I'm trying now to find an optimal way to use resources of Service Fabric node as much as possible. So I see 2 approaches: 1) create several threads inside the service 2) create several instances of the service per node. I consider that the 2nd way is more safe and correct but when I specified InstanceCount = 5 for 1-node cluster I received a warning.
Config.xml
<?xml version="1.0" encoding="utf-8"?>
<Application xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="fabric:/EmailSenderApp" xmlns="http://schemas.microsoft.com/2011/01/fabric">
<Parameters>
<Parameter Name="MainService_InstanceCount" Value="1" />
...
</Parameters>
</Application>
Error:
Unhealthy event: SourceId='System.FM', Property='State', HealthState='Warning', ConsiderWarningAsError=false.
Partition is below target replica or instance count.
fabric:/EmailSenderApp/EmailSenderMainService 5 1 09916a6b-1701-46ce-a281-0e223a68f980
Ready _Node_0 131708550454646056
(Showing 1 out of 1 instances. Total available instances: 1)
回答1:
As mentioned by @Diego Mendes this isn't possible.
Based on the documentation I would say that Service Fabric expects the instance of service to be able to utilize all available resources and report the appropriate metrics to allow Cluster Manager service to balance the load between nodes in a cluster.
In case when there is not enough available resource the scaling is done in term of nodes i.e. additional nodes should be added to the cluster and in case of stateless service (if InstanceCount=-1) it will automatically create new instances.
回答2:
Currently is not possible do have more than one primary partition on same node.
SF has placement constraints to block this, My opinion is that it is a bug, b because there is no concern on loosing state on stateless service, for this reason I've opened a GitHub issue to Allow singleton stateless services to have multiple instances per node bypassing placement constraint
To sort this issue, I guide you to this answer with options for solving a similar problem:
Simulate 10,000 Azure IoT Hub Device connections from Azure Service Fabric cluster
来源:https://stackoverflow.com/questions/50349125/more-than-one-instance-of-stateless-service-per-node