运行 Windows 服务作为 Service Fabric 中的有状态服务

Running a Windows Service as a statefull service in Service Fabric

我目前有三个 .net 程序 运行 作为 windows 服务。我们正在迁移到 Service Fabric,我有几个问题。我们的目的是将服务迁移到 StateFul 服务,因为我们需要跟踪当前存储在 app.config 文件中的文件位置、批处理大小等。所以我们可以 "lift and shift" 从 onTimer 事件到 RunAsync 的代码,正如这个 Whosebug 问题中所讨论的那样: How to Migrate Windows Service in Azure Service Fabric

但是我对这些服务有一些疑问。当然使用 SF 的一部分是让应用程序处于可靠的环境中,以尽可能地保持这些应用程序可用,所以第一个问题是:

Should we only deploy the service to one node and use the reliable 
collection to maintain the state of the process should the node go down and 
have to be brought back up?  

Or, should we deploy the application to say 3 nodes and just have each 
application on their node check the reliable collection to see if another 
application is processing files and to wait? 
files?

应用程序将"awake"在确定的时间间隔内查看文件夹,如果文件夹中有任何文件,它将处理它们。这可能需要几秒钟到几分钟的时间。因此,如果应用程序位于三个节点上,则它们节点上的其他两个应用程序完全有可能唤醒以处理文件。如果他们可以检查可靠的字典以查看应用程序的其他实例之一是否正在 运行 文件处理,他们就会等到下一次需要它们时。

我知道这很模糊,我正在寻找关于是在多个节点上还是在单个节点上启动应用程序的意见?

简而言之:有状态服务有 partitioned data. So you will have at least one, and probably more than one, partition. For each partition a primary instance will be up and running serving requests or doing work. Then for each primary instance there will be some secundary instances that will take over when the primairy fails. More info here.

在服务配置中指定分区数和副本数:

<Service Name="Processing">
<StatefulService ServiceTypeName="ProcessingType" TargetReplicaSetSize="[Processing_TargetReplicaSetSize]" MinReplicaSetSize="[Processing_MinReplicaSetSize]">
    <UniformInt64Partition PartitionCount="[Processing_PartitionCount]" LowKey="0" HighKey="25" />
</StatefulService>
</Service>

primairy 和 secundairy 实例(副本)将分布在集群节点上,例如,当节点 运行 primairy 实例出现故障时,另一个节点上的副本将接管。

它比我描述的要多,但这是它背后的基本思想。

所以回答你的问题:你应该在其他节点上指定足够的副本以保证高可用性。