缺点,高的工作价值 [英] Disadvantages to high make job values

查看:91
本文介绍了缺点,高的工作价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在make中使用更高的作业值 -j 是否有任何不利?

Is there any disadvantage to using a higher job value -j in make?

,建议对8个作业使用 make -j8 以加快进程。我很好奇简单使用更多工作的缺点,例如 make -j16 。当我尝试它,它似乎工作正常。使用更高的值有什么问题吗?为什么大多数项目使用-j8作为建议值?

In most installation READMEs, it is suggested to use make -j8 for 8 jobs to speed up the process. I am curious as to the disadvantages of simply using more jobs, for example make -j16. When I tried it, it seemed to work fine. Is there any problem with using higher values? Why do most projects use -j8 as the suggested value?

推荐答案

在makefile中禁止先决条件语句中的错误,使用更高的 -j 值可能会导致正确性正确性。但是,肯定会有性能问题。 没有免费午餐,你的构建不会只是继续获得更快的你的 -j 价值。在某些时候,你不会得到任何进一步的改进,但你实际上会得到增加的构建时间,就像你在同一时间在系统上运行太多的程序一样,他们都减慢。

Barring errors in the prerequisite statements in your makefile, there's no correctness issue with using higher -j values. However, there are definitely performance concerns. There's no free lunch and your build will not just continue to get faster forever the higher your -j value. At some point not only will you not get any more improvement but you will actually get increased build times, just the same as when you run too many programs on your system at the same time, they all slow down.

没有理由特别选择8,任何地方表明,作为一个总是最好的硬编码值应该被视为一个有用的资源:它们只是冒充他们从别人那里听到的东西,或者想出自己,而不理解它的意思。

There's no reason to choose 8 in particular, and anyplace that suggests that as a hardcoded value that is always the best should be dismissed as a useful resource: they are merely parroting something they heard from someone else, or came up with themselves, without understanding what it means.

真正的价值取决于你的硬件,(b)您的操作系统和(c)您的食谱调用的命令类型。

The real value that works well depends very heavily on (a) your hardware, (b) your operating system, and (c) the kinds of commands being invoked by your recipes.

例如,如果您有一个单核,双核,系统然后使用 -j8 可能不会很好地为您工作。这意味着八个不同的编译器都同时竞争有限的CPU资源,这意味着操作系统将不断地(它需要时间)交换它们,而不是让它们在没有上下文切换的情况下运行到完成。在具有24个内核的系统上,运行 -j8 会使大部分空闲。

For example, if you have a single-core, or even a dual-core, system then using -j8 will likely not work well for you. That means eight different compilers all competing for the limited CPU resources at the same time, which means the operating system will be swapping them in and out constantly (which takes time) rather than letting them run to completion without context switches. On systems with 24 cores, running -j8 would leave most of them idle.

核心和作业之间的一一对应是最好的?这是一个很好的起点,但还有其他的事情要考虑。首先,其他事情也在你的电脑上运行,所以也许core-1是更好?第二,编译器也必须读取和写入磁盘,磁盘访问非常慢(与CPU相比),所以当一个编译器作业正在等待磁盘I / O时,其他编译器作业可能正在进行有用的CPU工作,因此也许核心+ 1或核心+ 2更好?第三,某些种类的编译是非常CPU密集型,而另一些不是:例如,编译C ++与大量的模板,虚拟化类层次结构,内联和高优化级别使用大量的CPU;用其非常直接,相对而言的编译模型编译C需要更少的CPU(因此I / O与CPU的比率更高,并且更多的作业可以并行运行)。

So does that mean that a 1-to-1 correspondence between cores and jobs is best? It's a good starting point, but there are other things to consider. First, other things run on your computer as well, so maybe cores-1 is better? Second, compilers also have to read from and write to the disk and disk access is very slow (compared to CPU), so while one compiler job is waiting for disk I/O, other compiler jobs could be doing useful CPU work, so maybe cores+1 or cores+2 is better? Third, some kinds of compiles are very CPU intensive while others are not: for example, compiling C++ with lots of templates, virtualized class hierarchies, inlines, and high optimization levels use lots of CPU; compiling C with its very straightforward, comparatively, compilation model takes much less CPU (and hence the ratio of I/O to CPU is higher and more jobs can run in parallel).

那么你应该使用什么?确定知道的唯一方法是做测试:使用增加的值 -j 运行构建,直到时间达到高原或开始增加。

So what should you use? The only way to know for certain is do tests: run your build with increasing values of -j until times either plateau, or start to increase.

我通常使用核心+ 2用于具有4到8个内核的系统(这些天常见)。如果你有核心的LOTS,你可以尝试类似核心+ 0.4 *核心或任何。

I typically use "cores + 2" for a system with 4 to 8 cores (common these days). If you have LOTS of cores you might try something like "cores + 0.4*cores", or whatever.

这篇关于缺点,高的工作价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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