一个应用程序中有多少个并发线程是很多? [英] How many simultaneous threads in an application is a lot?

查看:63
本文介绍了一个应用程序中有多少个并发线程是很多?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

5、100、1000?

5, 100, 1000?

我想,这取决于",但取决于什么?

I guess, "it depends", but on what?

在作为服务器守护程序/服务运行的应用程序中,什么是常见的?

What is common in applications that run as server daemons / services?

什么是硬限制?

鉴于机器可以处理整体工作负载,我如何确定开销开始对性能产生影响的线程数是多少?

Given that the machine can handle the overall workload, how do I determine at how many threads the overhead starts to have an impact on performance?

操作系统之间的重要区别是什么?

What are important differences between OS's?

还应该考虑什么?

我之所以这么问是因为我想在应用程序中使用线程来组织我的应用程序的子组件,这些子组件不共享数据并且旨在并行执行它们的工作.由于应用程序还会使用线程池来并行化一些任务,我想知道我应该从什么时候开始考虑将要运行的线程总数.

I'm asking because I would like to employ threads in an application to organize subcomponents of my application that do not share data and are designed to do their work in parallel. As the application would also use thread pools for parallelizing some tasks, I was wondering at what point I should start to think about the number of threads that's going to run in total.

我知道 n+1 规则是确定同时处理同一任务以获得性能的线程数量的指导原则.但是,我想使用线程,就像可能在更大范围内使用进程一样,即.e.组织不应该相互干扰的独立任务.

I know the n+1 rule as a guideline for determining the number of threads that simultaneously work on the same task to gain performance. However, I want to use threads like one might use processes in a larger scope, i. e. to organize independent tasks that should not interfere with each other.

这个相关问题中,由于增加了复杂性,有些人建议尽量减少线程数.对我来说,线程似乎还可以帮助使事情更有序地排序并实际上减少干扰.对不对?

In this related question, some people advise to minimise the number of threads because of the added complexity. To me it seems that threads can also help to keep things sorted more orderly and actually reduce interference. Isn't that correct?

推荐答案

我无法回答您关于多少是多少"的问题,但我同意您不应该将线程用于所有可能的任务.

I can't answer your question about "how much is many" but I agree that you should not use threads for every task possible.

用于应用程序性能的最佳线程数量是 (n+1),其中 n 是您的计算机/claster 的处理器/内核数量.

The optimal amount of threads for performance of application is (n+1), where n is the amount of processors/cores your computer/claster has.

您的实际线程数量与 n+1 的差异越大,它获得的优化就越少,并且您的系统资源浪费在线程计算上.

The more your actual thread amount differs from n+1, the less optimal it gets and gets your system resources wasted on thread calculations.

因此,通常您将 1 个线程用于 UI,1 个线程用于一些通用任务,以及 (n+1) 个线程用于一些大型计算任务.

So usually you use 1 thread for the UI, 1 thread for some generic tasks, and (n+1) threads for some huge-calculation tasks.

这篇关于一个应用程序中有多少个并发线程是很多?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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