需要 WCF 设计方面的帮助
我的任务是创建一组网络服务。我们是一家 Microsoft 商店,因此我将在该项目中使用 WCF。有一个有趣的设计考虑,我还没有找到解决方案。我将尝试用一个示例来解释它:
我的 WCF 服务公开了一个名为 Foo() 的方法。
10 个不同的用户大致在同一时间调用 Foo()。
我有 5 个特殊资源,称为 R1、R2、R3、R4 和 R5。我们实际上并不需要知道资源是什么,除了特定资源一次只能由一个调用者使用这一事实之外。
Foo() 负责使用这些特殊资源之一执行操作。因此,以循环方式,Foo() 需要找到未使用的资源。如果没有可用资源,则必须等待资源被释放。
乍一看,这似乎是一项容易的任务。我也许可以创建一个单例来跟踪当前正在使用的资源。最大的问题是我需要这个解决方案在网络场场景中可行。
我确信这个问题有一个很好的解决方案,但我以前从未遇到过这种情况。我需要某种可以在多个 WCF 主机之间共享的资源跟踪器/提供程序。
来自建筑师的任何想法将不胜感激!
I have been tasked with creating a set of web services. We are a Microsoft shop, so I will be using WCF for this project. There is an interesting design consideration that I haven't been able to figure out a solution for yet. I'll try to explain it with an example:
My WCF service exposes a method named Foo().
10 different users call Foo() at roughly the same time.
I have 5 special resources called R1, R2, R3, R4, and R5. We don't really need to know what the resource is, other than the fact that a particular resource can only be in use by one caller at a time.
Foo() is responsible to performing an action using one of these special resources. So, in a round-robin fashion, Foo() needs to find a resource that is not in use. If no resources are available, it must wait for one to be freed up.
At first, this seems like an easy task. I could maybe create a singleton that keeps track of which resources are currently in use. The big problem is the fact that I need this solution to be viable in a web farm scenario.
I'm sure there is a good solution to this problem, but I've just never run across this scenario before. I need some sort of resource tracker / provider that can be shared between multiple WCF hosts.
Any ideas from the architects out there would be greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
创建另一个只有 Web 服务知道的中央服务。该服务承担资源管理器的角色。
场中的所有 Web 服务都将与该中央服务通信,以查询资源可用性以及“签出”和“签入”资源。
Create another central service which only the web services know about. This service takes on the role of the resource manager.
All of the web services in the farm will communicate with this central service to query for resource availability and to "check out" and "check in" resources.
您可以跟踪数据库表中的资源使用情况,场中的所有服务器都可以访问该表。
每个资源都会在数据库中拥有一条记录,其中的字段指示它是否(或何时)正在使用。您也可以花哨并实现超时功能。
为了进行故障排除,您还可以记录谁正在使用该资源。
如果您记录每个资源的使用时间(在另一个表中),您将能够验证您的循环是否按预期运行,决定是否应该添加更多资源副本等。
You could track the resource usage in a database table, which all the servers on the farm could access.
Each resource would have a record in the database, with fields that indicate whether (or since when) it is in use. You could get fancy and implement a timeout feature as well.
For troubleshooting purposes, you could also record who is using the resource.
If you record when each resource is being used (in another table), you would be able to verify that your round-robin is functioning as you expect, decide whether you should add more copies of the resource, etc.
解决这个问题的方法有很多种,每种方法都有各自的成本和收益。例如:
唉
,您没有指出您的请求是否必须在断电后生存,是否需要事务感知,调用者是否也是 WCF,接收这些调用的速度有多快,Rn 返回需要多长时间无论
您选择哪种解决方案,我强烈建议您将对 Foo() 的调用拆分为 RequestFoo() 和 GetFooResponse() 对,或者实现由调用者托管的 WCF 回调以异步接收结果。
如果您不这样做,您可能会发现,当第二个流量超出您的资源满足工作负载的能力时,您的整个系统将陷入停顿。
There are any number of approaches to solving this problem, each with their own costs and benefits. For example:
etc.
Alas, you don't indicate whether your requests have to survive power outages, if they need to be transactionally aware, whether the callers are also WCF, how quickly these calls will be received, how long it takes for Rn to return with results, etc.
Whichever solution you choose, I strongly encourage you to split your call to Foo() into a RequestFoo() and GetFooResponse() pair or implement a WCF callback hosted by the caller to receive results asynchronously.
If you do NOT do this, you're likely to find that your entire system will grind to a halt the second traffic exceeds your resources' abilty to satisfy the workload.