简体   繁体   English

Service Fabric如何选择托管服务的端口?

[英]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: 我的问题是:

  1. How does service fabric choose a port to host a service replica at? 服务结构如何选择一个端口来托管服务副本?
  2. Is the port sharing problem for secondary replicas only a problem for local development where I am physically on the same machine? 辅助副本的端口共享问题只是我在同一台机器上的本地开发问题吗? (I would assume that a replica in a real cluster will be placed on a different fault/upgrade domain) (我假设真实集群中的副本将放在不同的故障/升级域上)

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: 有几种方法可以解决这个问题:

  1. Use a networking stack that supports port sharing. 使用支持端口共享的网络堆栈。 On Windows, you have the Windows HTTP Server API (used by HttpListener and anything built on top of it, such as Katana) and WCF. 在Windows上,您拥有Windows HTTP Server API(由HttpListener使用,以及在其上构建的任何内容,例如Katana)和WCF。
  2. Use exclusive host processes instead, in which case every replica gets its own host process and therefore its own unique port. 使用独占主机进程 ,在这种情况下,每个副本都有自己的主机进程,因此它自己的唯一端口。 Process isolation also has a number of other benefits (eg, if a replica crashes the host process, it doesn't bring down other replicas with it) at the cost of increased resource consumption on the machine. 进程隔离还有许多其他好处(例如,如果副本崩溃主机进程,它不会使其中的其他副本失效),代价是机器上的资源消耗增加。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM