为什么相比于常规的CLR线程是IIS线程,以便precious? [英] Why are IIS threads so precious as compared to regular CLR threads?

查看:146
本文介绍了为什么相比于常规的CLR线程是IIS线程,以便precious?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

阅读AsyncControllers在ASP 的。 NET MVC。

I'm reading about AsyncControllers in ASP.NET MVC.

看来,为什么存在的唯一原因是为了让IIS线程可以同时长时间运行的工作委托给正规的CLR线程,似乎要便宜保存。

It seems that the sole reason why they exist is so that the IIS threads can be saved while the long running work is delegated to regular CLR threads, that seem to be cheaper.

我有几个问题在这里:


  • 为什么这些IIS线程这么贵证明这个整体架构上,支持异步控制器?

  • 我怎么知道/线程配置多少IIS在我​​的IIS应用程序池中运行?

推荐答案

ASP.NET处理由使用线程从.NET线程池的请求。线程池认为,已经发生的线程的初始化成本线程池。因此,这些线程是易于重用。在.NET线程池也自我调整。它可以监视CPU和其他资源的利用率,并增加了新的主题或根据需要修剪线程池的大小。通常应该避免手动创建线程来执行工作。相反,使用线程的线程池。与此同时,重要的是要确保您的应用程序不执行长时间阻塞操作,可能迅速导致线程池饥饿和拒绝的HTTP请求。​​

ASP.NET processes requests by using threads from the .NET thread pool. The thread pool maintains a pool of threads that have already incurred the thread initialization costs. Therefore, these threads are easy to reuse. The .NET thread pool is also self-tuning. It monitors CPU and other resource utilization, and it adds new threads or trims the thread pool size as needed. You should generally avoid creating threads manually to perform work. Instead, use threads from the thread pool. At the same time, it is important to ensure that your application does not perform lengthy blocking operations that could quickly lead to thread pool starvation and rejected HTTP requests.

磁盘I / O,Web服务调用,都被封锁。有使用异步调用最优化。当你做一个异步调用,asp.net释放你的线程,并请求将被分配到当回调函数被调用另一个线程。

Disk I/O, web service calls, are all blocking. There are best optimized by using async calls. When you make an async call, asp.net frees your thread and the request will be assigned to another thread when the callback function is invoked.

要配置的线程数您可以设置:

To configure the number of threads you can set:

<system.web>
    <applicationPool maxConcurrentRequestsPerCPU="50" maxConcurrentThreadsPerCPU="0" requestQueueLimit="5000"/>
</system.web>

参见:<一href=\"http://blogs.msdn.com/b/tmarq/archive/2007/07/21/asp-net-thread-usage-on-iis-7-0-and-6-0.aspx\">ASP.NET在IIS 7.5线程使用情况,IIS 7.0和IIS 6.0

这些都是设置, Microsoft最佳实践建议的:


  • 设置MAXCONNECTION 12 *#CPU的。此设置控制,你可以从客户端开始传出的HTTP连接的最大数目。在这种情况下,ASP.NET是客户端。 MAXCONNECTION设置到12 *#CPU的。

  • 设置maxIoThreads 100 。此设置控制I / O线程在.NET线程池的最大数量。该数目由可用的CPU的数量自动相乘。设置maxloThreads为100。

  • 设置maxWorkerThreads 100 。此设置控制工作线程在线程池的最大数目。这个号码,然后自动通过可用的CPU的数量成倍增加。设置maxWorkerThreads设置为100。

  • 设置minFreeThreads 88 *#CPU的。此设置使用的工作进程队列中的所有传入的请求,如果可用线程的线程池中的数量低于此设置的值。该设置有效地限制了可以同时向maxWorkerThreads minFreeThreads运行请求的数目。将minFreeThreads 88 CPU的*#。这限制并发请求的数目为12(假定maxWorkerThreads是100)。

  • 设置minLocalRequestFreeThreads 76 *#CPU的。此设置使用的工作进程排队本地请求(如Web应用程序将请求发送到本地Web服务),如果可用线程的线程池中的数量低于这个数字。此设置是类似于minFreeThreads但它只适用于从本地计算机本地主机的请求。设置minLocalRequestFreeThreads 76 *#CPU的。

  • Set maxconnection to 12 * # of CPUs. This setting controls the maximum number of outgoing HTTP connections that you can initiate from a client. In this case, ASP.NET is the client. Set maxconnection to 12 * # of CPUs.
  • Set maxIoThreads to 100. This setting controls the maximum number of I/O threads in the .NET thread pool. This number is automatically multiplied by the number of available CPUs. Set maxloThreads to 100.
  • Set maxWorkerThreads to 100. This setting controls the maximum number of worker threads in the thread pool. This number is then automatically multiplied by the number of available CPUs. Set maxWorkerThreads to 100.
  • Set minFreeThreads to 88 * # of CPUs. This setting is used by the worker process to queue all the incoming requests if the number of available threads in the thread pool falls below the value for this setting. This setting effectively limits the number of requests that can run concurrently to maxWorkerThreads minFreeThreads. Set minFreeThreads to 88 * # of CPUs. This limits the number of concurrent requests to 12 (assuming maxWorkerThreads is 100).
  • Set minLocalRequestFreeThreads to 76 * # of CPUs. This setting is used by the worker process to queue requests from localhost (where a Web application sends requests to a local Web service) if the number of available threads in the thread pool falls below this number. This setting is similar to minFreeThreads but it only applies to localhost requests from the local computer. Set minLocalRequestFreeThreads to 76 * # of CPUs.

注意:本节中提供的建议并非规则。它们是一个起点。

Note: The recommendations that are provided in this section are not rules. They are a starting point.

您将不得不基准测试您的应用程序,以找到最适合您的应用程序。

You would have to benchmark your application to find what works best for your application.

这篇关于为什么相比于常规的CLR线程是IIS线程,以便precious?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆