我目前正在测试我的应用程序的扩展,但遇到了一些我没有预料到的问题。
该应用程序在一个 5 节点集群上运行,它有多个服务/actortypes 并使用共享进程模型。
对于某些组件,它使用 actor 事件作为尽力而为的 pubsub 系统(有回退,因此如果删除通知,则没有问题)。
当参与者的数量增加(又名订阅主题)时,问题就会出现。目前,actorservice 被划分为 100 个分区。
此时的主题数量约为 160.000,其中每个主题订阅了 1-5 次(需要它的节点),平均订阅量为 2.5 个(大约 40 万个订阅)。
那时集群中的通信开始中断,不会创建新订阅,取消订阅超时。
但它也影响其他服务,对诊断服务的内部调用超时(询问 5 个副本中的每一个),这可能是由于分区/副本端点的解析,因为对网页的外部调用很好(这些端点使用相同的技术/代码堆栈)。
事件查看器充满了警告和错误,例如:
EventName: ReplicatorFaulted Category: Health EventInstanceId {c4b35124-4997-4de2-9e58-2359665f2fe7} PartitionId {a8b49c25-8a5f-442e-8284-9ebccc7be746} ReplicaId 132580461505725813 FaultType: Transient, Reason: Cancelling update epoch on secondary while waiting for dispatch queues to drain will result in an invalid state, ErrorCode: -2147017731
10.3.0.9:20034-10.3.0.13:62297 send failed at state Connected: 0x80072745
Error While Receiving Connect Reply : CannotConnect , Message : 4ba737e2-4733-4af9-82ab-73f2afd2793b:382722511 from Service 15a5fb45-3ed0-4aba-a54f-212587823cde-132580461224314284-8c2b070b-dbb7-4b78-9698-96e4f7fdcbfc
我试过扩展应用程序,但没有激活此订阅模型,我很容易达到两倍大的工作负载,没有任何问题。所以有几个问题
最佳答案
在与支持票一起度过一段时间后,我们找到了一些信息。所以我会在这里发布我的发现,以防它对某人有所帮助。
Actor 事件使用重新订阅模型来确保它们仍然连接到 Actor 。默认情况下每 20 秒执行一次。这意味着大量资源被使用,最终整个系统因等待重新订阅的空闲线程负载而过载。
您可以通过设置 resubscriptionInterval
来减少负载订阅时设置为更高的值。缺点是这也意味着客户端可能会同时错过事件(如果分区被移动)。
为了抵消重新订阅的延迟,可以 Hook 到较低级别的服务结构事件。在支持电话中向我提供了以下伪代码。
fabricClient.ServiceManager.ServiceNotificationFilterMatched += (o, e) =>
{
var notification = ((FabricClient.ServiceManagementClient.ServiceNotificationEventArgs)e).Notification;
/*
* Add additional logic for optimizations
* - check if the endpoint is not empty
* - If multiple listeners are registered, check if the endpoint change notification is for the desired endpoint
* Please note, all the endpoints are sent in the notification. User code should have the logic to cache the endpoint seen during susbcription call and compare with the newer one
*/
List<long> keys;
if (resubscriptions.TryGetValue(notification.PartitionId, out keys))
{
foreach (var key in keys)
{
// 1. Unsubscribe the previous subscription by calling ActorProxy.UnsubscribeAsync()
// 2. Resubscribe by calling ActorProxy.SubscribeAsync()
}
}
};
await fabricClient.ServiceManager.RegisterServiceNotificationFilterAsync(new ServiceNotificationFilterDescription(new Uri("<service name>"), true, true));
将分区 id 缓存到 actor id 映射。当副本的主要端点更改时,此缓存将用于重新订阅(引用 #1)
await actor.SubscribeAsync(handler, TimeSpan.FromHours(2) /*Tune the value according to the need*/);
ResolvedServicePartition rsp;
((ActorProxy)actor).ActorServicePartitionClientV2.TryGetLastResolvedServicePartition(out rsp);
var keys = resubscriptions.GetOrAdd(rsp.Info.Id, key => new List<long>());
keys.Add(communicationId);
上述方法确保以下这结束了来自支持调用的伪代码。
回答我原来的问题:
没有硬性限制,只有资源使用。
是的,资源争用就是原因。
关于azure-service-fabric - 服务结构中的actorevents有哪些限制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66382403/