如何在ApplicationManifest.xml中配置Service Fabric放置策略?
Service Fabric 无状态服务对应 ApplicationManifest.xml 配置
核心配置对应关系
以下是你提到的 PowerShell 参数对应的 ApplicationManifest.xml 等效配置,包含Singleton 分区、ExclusiveProcess 激活模式和AllowMultipleStatelessInstancesOnNode 放置策略:
完整配置示例
<?xml version="1.0" encoding="utf-8"?> <ApplicationManifest xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ApplicationTypeName="YourAppType" ApplicationTypeVersion="1.0.0" xmlns="http://schemas.microsoft.com/2011/01/fabric"> <Parameters> <Parameter Name="YourStatelessService_InstanceCount" DefaultValue="-1" /> </Parameters> <ServiceManifestImport> <ServiceManifestRef ServiceManifestName="YourStatelessServicePkg" ServiceManifestVersion="1.0.0" /> <ConfigOverrides /> <Policies> <!-- AllowMultipleStatelessInstancesOnNode 放置策略 --> <ServicePlacementPolicy Type="AllowMultipleStatelessInstancesOnNode" /> </Policies> </ServiceManifestImport> <DefaultServices> <Service Name="YourStatelessService"> <StatelessService ServiceTypeName="YourStatelessServiceType" InstanceCount="[YourStatelessService_InstanceCount]"> <!-- Singleton 分区配置 --> <SingletonPartition /> <!-- ExclusiveProcess 激活模式配置 --> <ActivationMode>ExclusiveProcess</ActivationMode> </StatelessService> </Service> </DefaultServices> </ApplicationManifest>
各参数对应说明
- Singleton 分区:通过
<SingletonPartition />节点直接配置,对应 PowerShell 中的-PartitionScheme Singleton参数。 - ExclusiveProcess 激活模式:在
<StatelessService>节点下添加<ActivationMode>ExclusiveProcess</ActivationMode>,确保每个服务实例在独立进程中运行,对应 PowerShell 的-ActivationMode ExclusiveProcess。 - AllowMultipleStatelessInstancesOnNode 放置策略:在
<ServiceManifestImport>下的<Policies>节点中添加<ServicePlacementPolicy Type="AllowMultipleStatelessInstancesOnNode" />,允许同一个节点上运行多个该服务的实例,对应 PowerShell 的-PlacementPolicy AllowMultipleStatelessInstancesOnNode。
验证要点
- 确保
ServiceTypeName、ServiceManifestName等名称与你的 ServiceManifest.xml 中的定义完全一致。 InstanceCount设为-1表示在每个节点上运行一个实例;若调整为大于-1的数值,结合放置策略会允许节点上运行多个实例。- 若需要资源限制,可在
<Policies>节点中添加<ServicePackageResourceGovernancePolicy CodePackageRef="Code" CpuCores="1" />,这是 ExclusiveProcess 模式下的可选配置。
内容的提问来源于stack exchange,提问作者Lokesh Lal
相关产品推荐
相关产品推荐

