问题
Suppose there is an named application running on Azure service fabric cluster. And this named application has 5 different services.
Will these services be running in different processes or in same process? And what if these services are not .net services and are executable?
回答1:
Guest EXEs always get their own processes.
Otherwise, there are two hosting modes available:
Exclusive Process - this one is very straight-forward so let's start here. In this mode, everything gets its own process. Every replica of every partition of every service instance of every application gets its own exclusive host process. This is my recommended hosting mode because it's the simplest, and that usually leads to much more stability and services that are much easier to debug.
Shared Process - this gets a little more complicated. Within an application instance, everything of the same service type shares a host process. So, for example, let's say you have one application:
fabric:/myapp
And in that application, you have two service types:
service-type-1 (stateful)
service-type-2 (stateless)
Now let's say you create an instance of service-type-1
with 5 partitions and 3 replicas per partition:
fabric:/myapp/mystateFULservice1 (service-type-1)
That gives you 15 replicas. With a 5 node cluster, Service Fabric will by default distribute things evenly, so you'll see 3 replicas on each node. In the shared host process model, the 3 replicas on each node will share a host process. Inside that host process, each replica is an instance of your class that derives from StatefulService
. Right away, you can see how this can get complicated. We're using C# constructs to represent replicas - each replica is a C# object. That means they share a process, address space, everything. If one of those replicas throws an unhandled exception and crashes the process, the others go down with it. And forget about using static variables!
Now let's say you create an instance of service-type-2
with an instance count = -1:
fabric:/myapp/mystateLESSservice1
Because this is a different service type, it will get its own host process, separate from the first service we created - it has to, because it's literally running different code/DLLs. This one is stateless, so for this instance of the service (fabric:/myapp/mystateLESSservice1) you'll only get one replica per node.
Now if you create another instance of service-type-2
, also with instance count = -1:
fabric:/myapp/mystateLESSservice2
That's the same service type, so that service instance will use the host process that's already up for the previous instance of that type, because they're running the same code/DLLs. This is analogous to what we saw with the stateful example - each service instance is really just an instance of your class that derives from StatelessService
, and this of course has all the same problems.
Finally, if you create a whole new application instance:
fabric:/myapp2
You get a whole new set of processes for everything in that application. So application instances are always process boundaries.
tl;dr: use Exclusive Process.
来源:https://stackoverflow.com/questions/47988059/does-azure-service-fabric-creates-separate-process-for-every-service