Service Fabric 动态分区

Service Fabric dynamic partitioning

所以我正在研究将 Service Fabric 用于非常大的应用程序。我需要的一件事是按名称分区的服务,这在应用程序清单级别似乎相当微不足道。

但是,我真的很希望能够即时添加和删除命名分区,而无需重新发布应用程序。

每个分区代表我们相当于一个租户,我们希望有一个后端管理应用程序来添加新租户。

每个分区都是一个长 运行 应用程序,它启动一个使用自定义协议的 TCP 服务器,我需要能够从集群中按名称查询地址。

Service Fabric 是否可以做到这一点?如果可以,是否有关于此的任何文档或我应该查找的内容?

无法更改现有应用程序的分区计数。 来自 https://azure.microsoft.com/en-us/documentation/articles/service-fabric-concepts-partitioning/#plan-for-partitioning(强调我的):

In rare cases, you may end up needing more partitions than you have initially chosen. As you cannot change the partition count after the fact, you would need to apply some advanced partition approaches, such as creating a new service instance of the same service type. You would also need to implement some client-side logic that routes the requests to the correct service instance, based on client-side knowledge that your client code must maintain.

我们鼓励您进行前期容量规划以确定您需要的最大分区数 - 如果您最终需要更多分区,则需要实施一些特殊的客户端处理来应对。

Each partition represents our equivalent of a tenant, and we want to have a backend management app to add new tenants.

您需要重新考虑您的模型。分区用于分配数据,以便快速访问数据以进行读写。但是在同一个逻辑容器中。

如果您想在 Service Fabric 中执行一些多租户操作,您可以将一个应用程序多次部署到集群。

从 Visual Studio 看来您只能拥有一个应用程序实例。这是因为在 ApplicationManifest.xml 中定义了 DefaultServices。这对于在本地 Service Fabric 群集上进行开发没有问题。对于生产,您可能需要考虑使用 powershell 部署应用程序,这将开启多次部署同一应用程序的可能性,并为每个实例设置(如:租户名称、安全性、...)

不仅应用程序可以多次部署,stateful/stateless 服务也可以。因此,您可以拥有一个应用程序,并为每个租户部署一种特定类型的服务。可以通过 Service Fabric 中的命名服务找到服务,有关详细信息,请参阅 FabricClient class。

我们遇到了同样的问题,最终为每个租户创建了一个服务实例。这很容易做到,并且可以扩展到任意数量的租户。