线程池SetMaxThreads和SetMinThreads幻数 [英] ThreadPool SetMaxThreads and SetMinThreads Magic Number

查看:3162
本文介绍了线程池SetMaxThreads和SetMinThreads幻数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个神奇的数字或公式设置SetMaxThreads和SetMinThreads的值线程池?我有成千上万需要执行长期运行的方法,但就是无法找到设置这些值的完美搭配。任何建议将不胜AP preciated。

Is there a magic number or formula for setting the values of SetMaxThreads and SetMinThreads for ThreadPool? I have thousands of long-running methods that need execution but just can't find the perfect match for setting these values. Any advise would be greatly appreciated.

推荐答案

默认线程最小数目为核心的机器有数目。这是一个不错的数字,它一般不会意义运行多个线程比你的核心。

The default minimum number of threads is the number of cores your machine has. That's a good number, it doesn't generally make sense to run more threads than you have cores.

默认线程最大数量是你有.NET 2.0 SP1及以上内核的250倍。这里有喘息空间巨大金额。在一个四核的机器,它会采取499秒达到了最大,如果没有一个线程完全在合理的时间量。

The default maximum number of threads is 250 times the number of cores you have on .NET 2.0 SP1 and up. There is an enormous amount of breathing room here. On a four core machine, it would take 499 seconds to reach that maximum if none of the threads complete in a reasonable amount of time.

的线程池调度尝试活动线程的数目限制到最小,默认情况下有核的数量。两次第二它允许一个更多话题开始,如果活动线程没有完成。对于很长一段时间运行,或做了很多的拦截不受I / O引发线程是不是线程池很好的候选人。你应该使用常规的线程来代替。

The threadpool scheduler tries to limit the number of active threads to the minimum, by default the number of cores you have. Twice a second it allows one more thread to start if the active threads do not complete. Threads that run for a very long time or do a lot of blocking that is not caused by I/O are not good candidates for the threadpool. You should use a regular Thread instead.

获取最大是不健康的。在一个四核的机器,这些线程只是堆栈将消耗虚拟内存空间千兆字节。获得OOM是非常可能的。考虑降低线程的最大数量,如果这是你的问题。或考虑开始只是接收工作的数据包从一个线程安全的队列一些常规线程。

Getting to the maximum isn't healthy. On a four core machine, just the stacks of those threads will consume a gigabyte of virtual memory space. Getting OOM is very likely. Consider lowering the max number of threads if that's your problem. Or consider starting just a few regular Threads that receive packets of work from a thread-safe queue.

这篇关于线程池SetMaxThreads和SetMinThreads幻数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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