NServiceBus 每消息一个分发器类型最佳实践背后的原因是什么?
我曾多次看到它被提到作为一种最佳实践,即每种消息类型应该配置一个分发器进程,但从未解释过为什么会这样。由于增加分销商的数量会增加部署的复杂性,我想知道其背后的原因。我的猜测是,如果给定消息类型的所有可用订阅者都忙,分发器可能会陷入等待其中一个空闲订阅者的状态,而可能有空闲订阅者的其他类型的消息则堆积在分发器的工作队列中。这准确吗?还有其他原因吗?
I have seen it mentioned several times as a best practice that there should be one distributor process configured per message type, but never any explanation as to why this is so. Since increasing the number of distributors increases the deployment complexity, I'd like to know the reasoning behind it. My guess is that if all available subscribers for a given message type are busy, the distributor may be stuck waiting for one to free up, while messages of other types which may have free subcribers are piling up in the distributor's work queue. Is this accurate? Any other reasons?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确实,在工人完成之前,分发者不会分发更多工作。因此,如果 Workers 与给定的消息类型相关,其他人将坐在那里直到完成。 NSB 没有优先级的概念,所有消息都是平等创建的。工作人员不订阅特定的消息类型,他们只是从分发者那里获得工作。
如果某些消息类型比其他消息类型具有“优先级”,那么它们应该有自己的分发器。如果“优先级”都相同,那么添加更多工作人员将在一定程度上提高性能。这将取决于您正在操作的资源。如果它是数据库,则您的端点的数据绑定可能比 CPU 绑定更多。在这种情况下,添加更多 Worker 不会有任何帮助,因为它们可能会增加对同一资源的争用。在这种情况下,您可能需要考虑如何对资源进行分区。
It is true that the Distributor will not hand out more work until a Worker is done. Therefore if Workers are tied up with a given message type, the others will sit there until they are done. NSB doesn't have a concept of priority, all messages are created equal. Workers do not subscribe to specific message types, they just get handed work from the Distributor.
If certain message types have "priority" over others, then they should have their own Distributor. If the "priority" is all the same then adding more workers will increase performance to a certain point. This will depend upon what you are resoruce you are operating upon. If it is a database, your endpoint may be more data bound than cpu bound. In that case adding more Workers won't help as they are creating increasing contention on potentially the same resource. In this case you may need to look into partitioning the resource some how.
每种消息类型都有一个逻辑端点(逻辑端点等于分发器后面的一个端点或端点的多个副本),使您能够灵活地独立监控和扩展每个用例。
此外,它还使您能够独立于所有其他消息类型对一种消息类型的端点进行版本控制。
由于安装了更多进程,因此部署复杂性更高,最终您必须(一如既往)在灵活性和复杂性之间取得平衡,但请记住,许多部署难题都可以自动化解决。
Having one logical endpoint per message type (logical endpoint is equal to either one endpoint or many copies of an endpoint behind a distributor) allows you the flexibility to monitor and scale each use case independently.
Also, it enables you to version the endpoint for one message type independently from all the others.
There is higher deployment complexity in that you have more processes installed, and ultimately you have to strike a balance (as always) between flexibility and complexity, but keep in mind that many of these deployment headaches can be automated away.