简体   繁体   English

合作框架中Linux中线程数的实际限制

[英]Practical limit on number of threads in Linux in a cooperative framework

So I know I can increase the number of threads of a process in Linux using setrlimit and friends. 所以我知道我可以使用setrlimit和朋友增加Linux中进程的线程数。 According to this , the theoretical limit on the number of threads is determined by memory (somewhere around 100,000k). 根据这一点 ,线程数的理论限制由内存决定(大约100,000k)。 For my use I'm looking into using the FIFO scheduler in a cooperative style, so spurious context switches aren't a concern. 对于我的使用,我正在考虑以协作方式使用FIFO调度程序 ,因此虚假的上下文切换不是一个问题。 I know I can limit the number of active threads to the number of cores. 我知道我可以将活动线程数限制为核心数。 My question is what the pratical limit on the number of threads are, after which assumptions in the scheduler start being voilated. 我的问题是线程数量的实际限制是什么,之后调度程序中的假设开始被消除。 If I maintain a true cooperative style are additional threads "free"? 如果我保持真正的合作风格是额外的线程“免费”? Any case studied or actual examples would be especially interesting. 研究的任何案例或实际的例子都会特别有趣。

The Apache server seems to be the most analagous program to this situation. Apache服务器似乎是最适合这种情况的程序。 Does anybody have any numbers related to how many threads they've seen Apache spawn before becoming useless? 有没有人有任何数字与他们在变得无用之前看到Apache产生了多少线程相关?

Related , but has to do with Windows, pre-emptive code. 相关 ,但与Windows,先发制人代码有关。

I believe the number of threads is limited 我相信线程数量有限

  1. by the available memory (each thread need at least several pages, and often many of them, notably for its stack and thread local storage). 通过可用内存(每个线程至少需要几个页面,通常需要很多页面,特别是它的堆栈和线程本地存储)。 See the pthread_attr_setstacksize function to tune that. 请参阅pthread_attr_setstacksize函数来调整它。 Threads stack space of a megabyte each are not uncommon. 每个兆字节的线程堆栈空间并不罕见。

  2. At least on Linux (NPTL ie current Glibc) and other systems where users threads are the same as kernel threads, but the number of tasks the kernel can schedule. 至少在Linux(NPTL,即当前的Glibc)和其他系统中,用户线程与内核线程相同,但内核可以调度的任务数量。

I would guess that on most Linux systems, the second limitation is stronger than the first. 我想在大多数Linux系统上,第二个限制比第一个更强。 Kernel threads (on Linux) are created thru the clone(2) Linux system call . 内核线程(在Linux上)是通过clone(2) Linux系统调用创建的 In old Unix or Linux kernels, the number of tasks was hardwired. 在旧的Unix或Linux内核中,任务数量是硬连线的。 It is probably tunable today, but I guess it is in the many thousands, not the millions! 它今天可能是可调的,但我猜它是成千上万,而不是数百万!

And you should consider coding in the Go language , its goroutines are the feather-light threads you are dreaming of. 你应该考虑使用Go语言进行编码,它的goroutines是你梦寐以求的轻盈线程。

If you want many cooperative threads, you could look into Chicken Scheme implementation tricks. 如果你想要很多合作线程,你可以查看Chicken Scheme实现技巧。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM