C# 异步远程调用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10670/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Asynchronous Remoting calls
提问by CVertex
We have a remoting singleton server running in a separate windows service (let's call her RemotingService). The clients of the RemotingService are ASP.NET instances (many many).
我们有一个在单独的 Windows 服务中运行的远程处理单例服务器(我们称她为 RemotingService)。RemotingService 的客户端是 ASP.NET 实例(很多)。
Currently, the clients remoting call RemotingService and blocks while the RemotingService call is serviced. However, the remoting service is getting complicated enough (with more RPC calls and complex algorithms) that the asp.net worker threads are blocked for a significantly long time (4-5 seconds).
当前,客户端远程调用 RemotingService 并在服务 RemotingService 调用时阻塞。但是,远程处理服务变得足够复杂(具有更多的 RPC 调用和复杂的算法),以至于 asp.net 工作线程被阻塞了很长时间(4-5 秒)。
According to this msdn article, doing this will not scale well because an asp.net worker thread is blocked for each remoting RPC. It advises switching to async handlers to free up asp.net worker threads.
根据这篇 msdn 文章,这样做不会很好地扩展,因为每个远程 RPC 都会阻塞一个 asp.net 工作线程。它建议切换到异步处理程序以释放 asp.net 工作线程。
The purpose of an asynchronous handler is to free up an ASP.NET thread pool thread to service additional requests while the handler is processing the original request.
异步处理程序的目的是在处理程序处理原始请求时释放 ASP.NET 线程池线程来为其他请求提供服务。
This seems fine, except the remoting call still takes up a thread from the thread pool. Is this the same thread pool as the asp.net worker threads?
这看起来很好,除了远程调用仍然从线程池中占用一个线程。这是与 asp.net 工作线程相同的线程池吗?
How should I go about turning my remoting singleton server into an async system such that I free up my asp.net worker threads?
我应该如何将我的远程单例服务器转变为异步系统,以便释放我的 asp.net 工作线程?
I've probably missed out some important information, please let me know if there is anything else you need to know to answer the question.
我可能遗漏了一些重要信息,如果您还有其他需要了解的信息来回答问题,请告诉我。
采纳答案by Vaibhav
The idea behind using the ThreadPool is that through it you can control the amount of synchronous threads, and if those get too many, then the thread pool automatically manages the waiting of newer threads.
使用 ThreadPool 背后的想法是,通过它您可以控制同步线程的数量,如果这些线程过多,则线程池会自动管理新线程的等待。
The Asp.Net worked thread (AFAIK) doesn't come from the Thread Pool and shouldn't get affected by your call to the remoting service (unless this is a very slow processor, and your remoting function is very CPU intensive - in which case, everything on your computer will be affected).
Asp.Net 工作线程 (AFAIK) 不是来自线程池,不应受到您对远程处理服务调用的影响(除非这是一个非常慢的处理器,并且您的远程处理功能非常占用 CPU - 其中情况下,您计算机上的所有内容都会受到影响)。
You could always host the remoting service on a different physical server. In that case, your asp.net worker thread will be totally independent of your remoting call (if the remoting call is called on a separate thread that is).
您始终可以在不同的物理服务器上托管远程处理服务。在这种情况下,您的 asp.net 工作线程将完全独立于您的远程调用(如果远程调用是在单独的线程上调用的)。