当使用服务器激活对象的 .NET Remoting 时,SingleCall 和 Singleton 激活之间的权衡是什么?

发布于 2024-07-12 07:41:47 字数 168 浏览 6 评论 0原文

在使用 .NET Remoting 实现服务器来托管对象时,我试图辨别 SingleCall 和 Singleton 激活方法之间的区别。 看起来 SingleCall 的开销是必须为每个客户端调用构造和清理对象,而 Singleton 的限制是只能服务有限数量的同时请求。 我希望使性能尽可能好。 我应该选择哪个?

I am trying to discern the difference between SingleCall and Singleton activation methods when implementing a server to host an object using .NET Remoting. It would appear that SingleCall has the overhead of having to construct and clean up an object for each client-side call, whereas Singleton has the limitation of only being able to service a limited number of simultaneous requests. I am looking to make performance as good as possible. Which should I choose?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

记忆里有你的影子 2024-07-19 07:41:47

你是对的。 SingleCall 为每个调用构建一个对象,并且可以接受多个同时请求,但数据不能在调用之间共享,而 Singleton 构建单个对象来处理允许数据共享的多个调用,但限制同时连接。 但是,如果您对如何构建线程安全对象有一些概念,则可以进行一些调整。

首先,我建议使用单例,因为它对于许多人来说只创建一次。 这还有一个优点,即允许您存储信息并在连接到该信息的用户之间共享信息,而无需经常访问外部存储。

其次,我会考虑将 ConcurrencyMode=ConcurrencyMode.Multiple 添加到服务的 ServiceBehaviors 中。 这允许多个用户同时访问您的单例。

[ServiceBehavior(ConcurrencyMode=ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.Single)] 
public class CalculatorService : ICalculatorConcurrency 
{ 
    …
}

第三,清理任何会使此类变得不线程安全的代码。 当访问多个线程可以同时访问的局部变量时,应该锁定该对象。

有关这些主题的大量有用信息可以在这里找到:

http://msdn。 microsoft.com/en-us/library/ms731193.aspx

You are right. SingleCall builds the object per each call and can accept multiple simultaneous requests, but data can't be shared between calls, while Singleton builds a single object to handle multiple calls allowing data sharing, but limits simultaneous connections. However, there are tweaks that you can do if you have some concept of how to build thread safe objects.

First, I would suggest using the Singleton as it is created only once for many. This also has the advantage of allowing you to store information and share it between users connecting to it without having to constantly hit an outside store.

Second, I would look into adding the ConcurrencyMode=ConcurrencyMode.Multiple into the ServiceBehaviors of your service. This allows multiple users to hit your singleton simultaneously.

[ServiceBehavior(ConcurrencyMode=ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.Single)] 
public class CalculatorService : ICalculatorConcurrency 
{ 
    …
}

Third, clean up any code that would make this class not thread safe. You should lock the object when accessing local variables that multiple threads could access simultaneously.

Lots of good information about these topics can be found here:

http://msdn.microsoft.com/en-us/library/ms731193.aspx

终止放荡 2024-07-19 07:41:47

默认情况下,您应该使用 SingleCall。

另外,请记住,使用 SingleCall 对象时,无法在调用之间共享状态。

我发现这个网站在 .NET 远程处理方面是一个很好的资源:
http://www.thinktecture.com/resourcearchive/net-remoting-faq/远程处理用例

By default, you should use SingleCall.

Also, keep in mind that, when using SingleCall objects, you cannot share state accross calls.

I found this site a good resource when it comes to .NET remoting:
http://www.thinktecture.com/resourcearchive/net-remoting-faq/remotingusecases

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文