How does Service Fabric choose the port to host the service?

I am in the middle of implementing GRPC on top of Service Fabric in C #. The GRPC server requires a ServerPort (responsible for binding ssl credentials to a port) and a service definition (responsible for mapping requests on the method delegate path). I created a Communication Listener that reports the partition and replica IDs along with the FQDN: port. This allows the client to keep track of the correct partition / replica properly. I was declaring an endpoint resource in the main service view and left the port empty to indicate that I want the service framework to assign a random port. My problem with local development (I haven't brought this to a cluster in azure area yet) is that the replicas seem to die because they are assigned the same port. I should also note that I am telling the listener to listen to secondary cues.

My question is:

  • How does the service fabric choose the port to host the service replica?
  • Is the issue of sharing ports for secondary replicas only an issue for local development where I am physically on the same machine? (I would assume a replica in a real cluster would be hosted in a different domain with a bug / update)
+3


source to share


1 answer


Service Fabric reserves the application port range defined in your cluster settings (in your resource manager template if you are hosting in Azure). When you leave a port empty in an endpoint resource, as you did, SF will pick a port from that range that has not yet been assigned to another service on the machine.

It is important to note that port mapping is for each host process, and host-process mode is shared , where replicas of the same service type can share the host process. In this case, replicas in the same host process will receive the same port.



There are several ways to handle this:

  • Use a network stack that supports port sharing. On Windows, you have the Windows HTTP Server API (used by the HttpListener and everything built on top of it, like Katana) and WCF.
  • Use exclusive host processes , in which case each replica gets its own host process and therefore its own unique port. Process isolation also has a number of other benefits (for example, if a replica destroys the host process, it does not reduce other replicas) at the expense of increasing resource consumption on the machine.
+1


source







All Articles