数百个空闲线程的影响 [英] Impact of hundreds of idle threads

查看:94
本文介绍了数百个空闲线程的影响的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑使用潜在的几百个线程来实现通过网络管理设备的任务。

I am considering the use of potentially hundreds of threads to implement tasks that manage devices over a network.

这是一个在带有Linux内核的powerpc处理器上运行的C ++应用程序。

This is a C++ application running on a powerpc processor with a linux kernel.

每个任务执行同步以将数据从设备复制到任务中,任务变为空闲,并且仅在其接收到警报时被唤醒,或者需要改变一些数据(配置),这在开始阶段之后是罕见的。一旦所有任务到达空闲阶段,我预计只有几秒钟的时间需要唤醒。

After an initial phase when each task does synchronization to copy data from the device into the task, the task becomes idle, and only wakes up when it receives an alarm, or needs to change some data (configuration), which is rare after the start phase. Once all tasks reach the "idle" phase, I expect that only a few per second will need to wake.

所以,我的主要关注是,如果我有数百线程会在系统空闲时对系统产生负面影响?

So, my main concern is, if I have hundreds of threads will they have a negative impact on the system once they become idle?

感谢。
amso

Thanks. amso

编辑:

我根据我得到的答案更新问题。多谢你们。
所以看来,有很多线程空闲(IO阻塞,等待,睡眠等),本身,将不会对系统响应性有影响。
当然,他们会为每个线程的堆栈和TLS数据花费额外的钱,但只要我们在这个东西(更多的€€€)投入更多的内存就可以了。

edit:
I'm updating the question based on the answers that I got. Thanks guys. So it seems that having a ton of threads idling (IO blocked, waiting, sleeping, etc), per se , will not have an impact on the system in terms of responsiveness. Of course, they will spend extra money for each thread's stack and TLS data but that's okay as long as we throw more memory at the thing (making it more €€€)

但是,其他问题必须考虑。由于需要等待队列或其他类似的资源,使100个线程等待可能增加内核上的内存使用。还有一个延迟问题,看起来是非确定性的。要检查每个解决方案的响应和内存使用情况,应该测量它并进行比较。

But then, other issues have to be accounted for. Having 100s of threads waiting will likely increase memory usage on the kernel, due to the need of wait queues or other similar resources. There's also a latency issue, which looks non-deterministic. To check the responsiveness and memory usage of each solution one should measure it and compare.

最后,几百个线程的大部分空闲的想法可以建模为一个线程池。这减少了一些代码线性,但是大大提高了解决方案的可扩展性,并且可以轻松地调整propper care以调整性能和资源使用之间的折中。

Finally, the whole idea of hundreds of threads that will be mostly idling may be modeled like a thread pool. This reduces a bit of code linearity but dramatically increases the scalability of the solution and with propper care can be easily tunable to adjust the compromise between performance and resource usage.

就这样。感谢所有人的输入。

I think that's all. Thanks everyone for their input.

-

amso

--
amso

推荐答案

每个线程都有开销 - 最重要的是每个线程都有自己的堆栈和TLS。性能不是那么多问题,因为他们不会得到任何时间片,除非他们真正做任何事情。您仍然可以考虑使用线程池。

Each thread has overhead - most importantly each one has its own stack and TLS. Performance is not that much of a problem since they will not get any time slices unless they actually do anything. You may still want to consider using thread pools.

这篇关于数百个空闲线程的影响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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