[英]ThreadPool SetMinThreads - the impact of setting it
I am trying to understand the impact of setting ThreadPool.SetMinthreads
. 我试图了解设置
ThreadPool.SetMinthreads
的影响。 I have multiple virtual applications running in one Azure App Service. 我在一个Azure App Service中运行了多个虚拟应用程序。 My understanding is that all these virtual applications will share the App Pool, and will have only one worker process (Assuming the App Pool's max worker process will be 1).
我的理解是,所有这些虚拟应用程序将共享应用程序池,并且只有一个工作进程(假设应用程序池的最大工作进程为1)。
I have the below two questions. 我有以下两个问题。
ThreadPool.SetMinThreads
to let's say 100 worker threads and IO threads, can I safely assume that each app domain will have 100 worker threads and 100 IO threads when it is loaded? ThreadPool.SetMinThreads
设置为100个工作线程和IO线程,是否可以安全地假定每个应用程序域在加载时将具有100个工作线程和100个IO线程? To be precise, the ThreadPool.SetMinThreads applies within the AppDomain, or Worker Process or App Pool? Process and threads, for example, require physical memory, virtual memory, and pool memory, so the number of processes or threads that can be created on a given Windows system is ultimately determined by one of these resources, depending on the way that the processes or threads are created and which constraint is hit first.
例如,进程和线程需要物理内存,虚拟内存和池内存,因此可以在给定Windows系统上创建的进程或线程的数量最终由这些资源之一确定,具体取决于进程的方式或创建线程,并首先遇到哪个约束。 https://blogs.technet.microsoft.com/markrussinovich/2009/07/05/pushing-the-limits-of-windows-processes-and-threads/
https://blogs.technet.microsoft.com/markrussinovich/2009/07/05/pushing-the-limits-of-windows-processes-and-threads/
The MinThreads governs how many worker threads will be spawned without a delay . 该MinThreads支配多少工作线程将没有延迟催生。
Whenever you do something that requires a thread from the thread pool (whether worker or IOCP pool), the system will first see if there is a free thread. 每当您执行需要线程池(工作线程或IOCP池)中的线程的操作时,系统都会首先查看是否有空闲线程。
If not, it looks to see how many threads are currently spawned. 如果不是,它将查看当前产生了多少个线程。 If that number is less than MinThreads, it immediately spawns a new thread.
如果该数字小于MinThreads,它将立即产生一个新线程。 Otherwise it waits a short time, usually around 300-500ms, though that is system dependent.
否则,它会等待一小段时间,通常约300-500ms,尽管这取决于系统。 If there is still no free thread, it will then spawn a new thread.
如果仍然没有空闲线程,它将生成一个新线程。
Of course, this all is still limited by MaxThreads. 当然,这仍然受MaxThreads的限制。
All that said, IIS is very good at figuring out a sensible number based on your machine and in most cases you are best to leave it alone; 综上所述,IIS非常擅长根据您的计算机确定一个合理的数字,在大多数情况下,最好不要理会它。 if you are just worried about serving requests then I wouldn't touch it personally.
如果您只是担心要处理请求,那么我不会亲自处理它。 If, on the other hand, you are spawning a lot of background tasks yourself then it may be sensible.
另一方面,如果您自己生成许多后台任务,那么这可能是明智的。 I'd strongly encourage you to measure it before you actually make changes.
我强烈建议您在实际进行更改之前先进行衡量。
Though... Setting MinThreads to 100 is rarely harmful, especially as the system will only start the number of threads it actually needs anyway 虽然...将MinThreads设置为100几乎没有害处,特别是因为系统无论如何只会启动它实际需要的线程数
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.