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

时间:2020-12-16 12:16:03

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?

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

2 个解决方案

#1


2  

By default, you should use SingleCall.

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

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

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

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

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

#2


3  

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.

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

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.

首先,我建议使用Singleton,因为它只为许多人创建一次。这样做的另一个好处是,您可以存储信息并在连接到它的用户之间共享信息,而无需经常访问外部商店。

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.

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

[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

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

#1


2  

By default, you should use SingleCall.

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

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

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

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

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

#2


3  

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.

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

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.

首先,我建议使用Singleton,因为它只为许多人创建一次。这样做的另一个好处是,您可以存储信息并在连接到它的用户之间共享信息,而无需经常访问外部商店。

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.

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

[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

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