[英]How does Service Fabric Choose a Port to Host a Service on?
I am in the middle of implementing GRPC on top of Service Fabric in C#. 我正在使用C#在Service Fabric上实现GRPC。 The GRPC Server requires a ServerPort (in charge of binding ssl credentials to a port) and a Service Definition (in charge of mapping requests on a path to a method delegate).
GRPC服务器需要ServerPort(负责将ssl凭证绑定到端口)和服务定义(负责在路径上映射请求到方法委托)。 I made a Communication Listener which reports the partition and replica ids along with the FQDN:port.
我做了一个通信监听器,它报告分区和副本ID以及FQDN:端口。 This allows the client to correctly ensure its talking to the right partition/replica.
这允许客户端正确地确保其与正确的分区/副本进行通信。 I declared an Endpoint resource in the service mainifest and left the port blank to indicate that I want service fabric to assign a random port.
我在服务mainifest中声明了一个Endpoint资源,并将端口留空,表示我希望service fabric分配一个随机端口。 My problem in local development (i haven't pushed this out to a cluster in azure yet) is that the replicas appear to die because they are assigned the same port.
我在本地开发中遇到的问题(我还没有把它推到天蓝色的集群中)是复制品似乎死了,因为它们被分配了相同的端口。 I should also note that I am telling the listener to listen on the secondary replicas.
我还应该注意,我告诉听众听二级副本。
My Question is: 我的问题是:
Service Fabric reserves an application port range which is defined in your cluster settings (in your Resource Manager template if you're hosting in Azure). Service Fabric保留应用程序端口范围,该范围在您的群集设置中定义(如果您在Azure中托管,则在Resource Manager模板中)。 When you leave the port blank in the Endpoint resource as you did, SF will pick a port from this range that has not already been assigned to another service on the machine.
当您将端口空白留在端点资源中时,SF将从此范围中选择尚未分配给计算机上其他服务的端口。
The important thing to note though is that the port allocation is per host process , and the default host process mode is shared host process, where replicas of the same service type can share a host process. 需要注意的重要一点是,端口分配是按主机进程进行的 ,默认主机进程模式是共享主机进程,其中相同服务类型的副本可以共享主机进程。 In that case, replicas in the same host process will get the same port.
在这种情况下,同一主机进程中的副本将获得相同的端口。
There are a couple ways to deal with this: 有几种方法可以解决这个问题:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.