.NET 线程池是否应该在启动时创建最少数量的工作线程?
Should .NET thread-pool create the minimum amount of worker threads at start-up?
假设一个 ASMX 服务应用程序托管在 Windows 服务器 2008r2、IIS 7.5、集成池、.net 4.0 CLR、64 位。它几乎是异步的并且被广泛使用的 TPL 库。
假设配置为 N 的 .NET 线程池最小工作线程在启动时强制创建 N 个工作线程是否正确?
我期待这种行为,但它不会发生或间歇性发生。
配置详情如下:
Machine.config 部分将其属性 'minWorkerThreads' 设置为 100,以便使用最少 100*CPUcount(假设 4 核桌面为 400)工作线程初始化线程池。
在服务应用程序启动 ThreadPool 之后。GetMinThreads(out minWorkerThreadsCount, out minIoThreadsCount) 按预期显示 minWorkerThreadsCount是 400.
尽管如此 调试 'Threads' window 仅显示 60 个线程 与任务管理器相同。似乎线程池回落到默认行为,但 minWorkerThreadsCount 仍然是 400.
有什么想法可以在 运行 时触发此类行为或减少线程数量?
据称,当应用程序是在 .NET 4.5 运行 时针对 .NET 4.0 构建时会出现此问题。
如有任何意见,我将不胜感激。
没有。它会快速增长到那个数字,而不是从那么多线程开始。
查看部分ThreadPool.SetMinThreads我强调:
Sets the minimum number of threads the thread pool creates on demand, as new requests are made, before switching to an algorithm for managing thread creation and destruction.
假设一个 ASMX 服务应用程序托管在 Windows 服务器 2008r2、IIS 7.5、集成池、.net 4.0 CLR、64 位。它几乎是异步的并且被广泛使用的 TPL 库。
假设配置为 N 的 .NET 线程池最小工作线程在启动时强制创建 N 个工作线程是否正确?
我期待这种行为,但它不会发生或间歇性发生。
配置详情如下: Machine.config 部分将其属性 'minWorkerThreads' 设置为 100,以便使用最少 100*CPUcount(假设 4 核桌面为 400)工作线程初始化线程池。
在服务应用程序启动 ThreadPool 之后。GetMinThreads(out minWorkerThreadsCount, out minIoThreadsCount) 按预期显示 minWorkerThreadsCount是 400.
尽管如此 调试 'Threads' window 仅显示 60 个线程 与任务管理器相同。似乎线程池回落到默认行为,但 minWorkerThreadsCount 仍然是 400.
有什么想法可以在 运行 时触发此类行为或减少线程数量? 据称,当应用程序是在 .NET 4.5 运行 时针对 .NET 4.0 构建时会出现此问题。
如有任何意见,我将不胜感激。
没有。它会快速增长到那个数字,而不是从那么多线程开始。
查看部分ThreadPool.SetMinThreads我强调:
Sets the minimum number of threads the thread pool creates on demand, as new requests are made, before switching to an algorithm for managing thread creation and destruction.