在同一节点上动态创建服务的Service Fabric进程隔离 [英] Service Fabric process isolation for dynamically created services on the same node

查看:110
本文介绍了在同一节点上动态创建服务的Service Fabric进程隔离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由两种服务类型组成的SF应用程序类型-无状态WebApi网关服务类型和无状态Worker服务类型.我正在使用默认网关服务实例创建一个应用程序实例.网关服务实例使用以下代码(client变量为System.Fabric.FabricClient实例)按需动态创建Worker服务实例:

I have an SF application type consisting of two service types – stateless WebApi Gateway service type and stateless Worker service type. I am creating one application instance with default Gateway service instance. The Gateway service instance creates Worker service instances dynamically on demand by using code like this (the client variable is the System.Fabric.FabricClient instance):

var serviceDescription = new StatefulServiceDescription()
{
  ApplicationName = new Uri("fabric:/Gateway"),
  ServiceName = new Uri("fabric:/Gateway/Worker-" + SomeUniqueWorkerId),
  ServiceTypeName = "WorkerType",
  HasPersistedState = true,
  PartitionSchemeDescription = new UniformInt64RangePartitionSchemeDescription(),
  MinReplicaSetSize = 1,
  TargetReplicaSetSize = 1
};
await client.ServiceManager.CreateServiceAsync(serviceDescription);

当SF将两个或多个Worker服务类型的实例放置到一个节点上时,它们都共享相同的进程(即Worker.exe).这是有问题的,因为不同的Worker服务实例需要从不同的文件共享中动态加载程序集的不同版本.因此,我的问题是:

When SF places two or more instances of the Worker service type onto one node, they all share the same process (i.e. Worker.exe). This is problematic because the different Worker service instances need to dynamically load different versions of assemblies from different file shares. Therefore, my question is:

是否可以强制SF在单独的进程中的一个节点上托管多个相同类型的服务实例?

Is it possible to force SF to host multiple service instances of the same type on one node in separate processes?

(我认为来宾可执行文件可以这样工作.)

(I think that guest executables work that way.)

推荐答案

您现在可以在创建服务时指定ServicePackageActivationMode.

You can now specify the ServicePackageActivationMode when creating services.

在默认模式下或将ServicePackageActivationMode设置为"SharedProcess"时,所有这些服务对象将在同一进程中运行.但是,通过指定ExclusiveProcess,每个服务对象最终将在其自己的进程中创建.假设您在一个简单的5节点群集上部署了这两个无状态服务.

With the default mode or with ServicePackageActivationMode set to "SharedProcess", all of these service objects would run in the same processes. However, by specifying ExclusiveProcess, each service object will end up created in its own process. Let's say that you had these two stateless services deployed on a simple 5 node cluster.

在共享|默认"模式下,您将获得5个进程,每个节点1个,每个进程内部运行2个服务对象.使用独占模式,您将获得10个进程,每个节点2个,每个进程中运行1个服务对象.

With the Shared|Default mode, you'd get 5 processes, one per node, each with 2 service objects running inside them. With the Exclusive mode, you get 10 processes, 2 per node, each with 1 service object running inside it.

New-ServiceFabricService -Stateless -PartitionSchemeSingleton -ApplicationName "fabric:/App" -ServiceName "fabric:/App/svc" -ServiceTypeName "T1" -InstanceCount -1 -ServicePackageActivationMode ExclusiveProcess New-ServiceFabricService -Stateless -PartitionSchemeSingleton -ApplicationName "fabric:/App" -ServiceName "fabric:/App/svc" -ServiceTypeName "T2" -InstanceCount -1 -ServicePackageActivationMode ExclusiveProcess

New-ServiceFabricService -Stateless -PartitionSchemeSingleton -ApplicationName "fabric:/App" -ServiceName "fabric:/App/svc" -ServiceTypeName "T1" -InstanceCount -1 -ServicePackageActivationMode ExclusiveProcess New-ServiceFabricService -Stateless -PartitionSchemeSingleton -ApplicationName "fabric:/App" -ServiceName "fabric:/App/svc" -ServiceTypeName "T2" -InstanceCount -1 -ServicePackageActivationMode ExclusiveProcess

在上面的示例中,您所需要做的就是添加

In your example above, all you need to do is add

ServicePackageActivationMode = ServicePackageActivationMode.ExclusiveProcess到您的ServiceDescription.

ServicePackageActivationMode = ServicePackageActivationMode.ExclusiveProcess to your ServiceDescription.

是一个好的文档,其中详细介绍了每个模型以及如何选择适合给定情况的模型.我最通常看到的是,它用来避免共享无法从服务代码中分解出来并由主机进程层拥有的静态信息.

This is a good piece of docs which goes into more detail about each model and how to choose which is right for a given situation. Most commonly I see it used to avoid sharing statics that can't be factored out of the service code and owned at the host process layer instead.

这篇关于在同一节点上动态创建服务的Service Fabric进程隔离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆