WCF 服务内部火灾/忘记队列
我目前正在使用 WCF 实现一项服务,该服务控制对 CRM 数据库的操作。我已经实现了 CQRS 的多个方面,将所有操作分为不同的命令和查询。
问题 1:
一些命令操作执行相对简单的操作,但会触发辅助的、通常更昂贵的操作。我已经分离了这些触发器,但它们仍然在原始操作线程中执行。
我正在考虑将它们分离到第二个 WCF 服务中,并进行单向操作。这样原始操作可以立即返回,并且“触发器”服务可以处理所有这些辅助操作。目前可靠性不是主要问题,因此问题记录就足够了 - 但将来可能会扩展。
这是处理这种情况的典型方法吗?或者有没有一种方法可以在不使用辅助服务的情况下完成此操作?
问题2:
在同一台服务器上这样划分WCF服务是否会带来显着的性能提升?
我的想法是,核心 WCF 服务的应用程序池将被更快地释放(尽管新的池将相互竞争),并且可以将附加服务分离到单独的服务器上。
I'm currently implementing a service using WCF, which controls operations to a CRM database. I've implemented several aspects of CQRS to separate all operations into distinct Command and Queries.
Question 1:
Several of the Command Operations perform a relatively simple operation, but trigger a secondary, often more expensive operation. I've separated these triggers, but they still execute within the original operation thread.
I was thinking of separating these into a second WCF service, with one-way operations. That way the original operation can return immediately, and the "Trigger" service can handle all of these secondary operations. Currently reliability is not a major issue, so issue logging would suffice - but could be extended in the future.
Is this the typical way for handling such a scenario? Or is there a way this could be completed without using a secondary service?
Question 2:
Are there significant performance improvements from dividing WCF services like this on the same server?
My thinking is that core WCF Service's application pool will be freed up quicker (although the new pools will be competing), with the possibility of separating additional services onto separate servers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我同意 oleksii 的观点,如果您希望扩展,队列可能是比 WCF 服务更好的选择。它还允许您将命令移动为单向,实际上只是向用户返回一个基本的 ack/nack,表明命令已收到并正在处理(而不是已处理)。
我建议您查看 Greg Young 在他的 CQRS Info 网站上对 CQRS 的介绍文档,特别是在命令侧部分(大约向下一半)。
回答您的问题:
我希望这有帮助。祝你好运!!
I agree with oleksii that a queue may be a better option than a WCF service if you're looking to scale. It will also allow you to move your commands to be one-way and really just return to the user a basic ack/nack that the command was received and is being processed (not that it was processed).
I'd suggest you look at Greg Young's intro to CQRS document on his CQRS Info site, specifically in the Command Side section (about half-way down).
Getting to your questions:
I hope this helps. Good luck!!
没有什么可以阻止您使用同步命令,然后仅异步运行部分执行代码,而无需分离服务。
你提到你已经分离了你的“触发器”。我认为这意味着它们作为单独的方法运行?既然如此,您可以轻松地在后台运行它们并让您的主 WCF 线程返回,而无需分离服务。 (下面的代码不假设事件源。)
如果您使用事件流和事件处理程序来执行数据库写入并与其他系统集成,那么这可以构造得更好一些。您可以让您的个人事件处理程序担心它是否应该同步执行。
There's nothing stopping you from having synchronous commands and then having only some of the execution code run asynchronously without having to separate services.
You mentioned that you have separated your "triggers". I assume that means they run as separate methods? That being the case, you can easily run them in the background and let your main WCF thread return, without having to separate services. (The code below is NOT assuming event sourcing.)
If you were using an event stream and event handlers to perform database writes and integrate with other systems, then this could be structured a bit better. You could have your individual event handlers worry about whether it should execute synchronously or not.
只是一个建议
你可以尝试一个工作队列,前端的一些服务异步添加项目。后端的其他服务使项目出列并处理工作。工作状态保存到可查询的持久存储中。
队列两侧最好都有多个工作人员,但对于任何改进,您的服务器需要是多核(多处理器)的,这样它将能够真正并行工作。您可能需要实际尝试不同的选项,看看什么是最好的。
Just a suggestion
You can try a working queue, some services on the front end asynchronously add items. Other services on the back end dequeue items and process the work. State of the work is saved to the persistent storage where it can be queried.
It's better to have several workers on both sides of the queue, but for any improvements, your server needs to be multi-core (multi-processor), so it will be able to truly parallelise work. You may need to actually try different options and see what's best.