gpt4 book ai didi

hadoop - YARN vcore中的virtual core是什么意思?

转载 作者:可可西里 更新时间:2023-11-01 14:26:32 24 4
gpt4 key购买 nike

Yarn 使用虚拟核心的概念来管理 CPU 资源。我会问使用虚拟核心有什么好处,YARN 使用虚拟核心有什么原因吗?

最佳答案

这是文档中的内容(强调我的)

A node's capacity should be configured with virtual cores equal to its number of physical cores. A container should be requested with the number of cores it can saturate, i.e. the average number of threads it expects to have runnable at a time.

除非 CPU 核心是超线程的,否则它一次只能运行一个线程(如果超线程操作系统实际上看到一个物理核心有 2 个核心并且可以运行两个线程 - 当然这有点作弊而且没有- 与拥有实际物理核心一样高效)。从本质上讲,它对最终用户意味着一个内核可以运行单个线程,因此从理论上讲,如果我想使用 Java 线程进行并行处理,那么一个相当好的近似值是线程数等于内核数。所以如果你的容器进程(这是一个 JVM)将需要 2 个线程,然后最好将其映射到 2 个 vcore——这就是最后一行的意思。作为节点的总容量,vcore 应该等于物理内核的数量。

要记住的最重要的事情仍然是,实际上是操作系统将调度线程在不同的内核中执行,就像在任何其他应用程序中发生的那样,并且YARN 本身没有控制它,除了什么是为每个容器分配多少线程的最佳近似值。这就是为什么重要的是要考虑在操作系统上运行的其他应用程序、内核使用的 CPU 周期等,因为所有内核并非始终对 YARN 应用程序可用。

编辑:进一步研究

Yarn 不会影响 CPU 的硬性限制,但通过代码我可以看到它如何试图影响 CPU 调度或 cpu 速率。从技术上讲,Yarn 可以启动不同的容器进程——java、python、自定义 shell 命令等。在 Yarn 中启动容器的责任属于节点管理器的 ContainerExecutor 组件,我可以看到用于启动容器等的代码,以及一些提示(取决于在平台上)。例如,在 DefaultContainerExecutor(它扩展了 ContainerExecutor)的情况下 - 对于 windows,它使用“-c”参数来限制 cpu,而在 linux 上,它使用进程 niceness 来影响它。还有另一个实现 LinuxContainerExecutor(或者更好的是 CgroupsLCEResourcesHandler,因为前者不强制使用 cgroups)试图使用 Linux cgroups 来限制该节点上的 Yarn CPU 资源。可以找到更多详细信息here .

ContainerExecutor {
.......
.......

protected String[] getRunCommand(String command, String groupId,
String userName, Path pidFile, Configuration conf, Resource resource) {
boolean containerSchedPriorityIsSet = false;
int containerSchedPriorityAdjustment =
YarnConfiguration.DEFAULT_NM_CONTAINER_EXECUTOR_SCHED_PRIORITY;

if (conf.get(YarnConfiguration.NM_CONTAINER_EXECUTOR_SCHED_PRIORITY) !=
null) {
containerSchedPriorityIsSet = true;
containerSchedPriorityAdjustment = conf
.getInt(YarnConfiguration.NM_CONTAINER_EXECUTOR_SCHED_PRIORITY,
YarnConfiguration.DEFAULT_NM_CONTAINER_EXECUTOR_SCHED_PRIORITY);
}

if (Shell.WINDOWS) {
int cpuRate = -1;
int memory = -1;
if (resource != null) {
if (conf
.getBoolean(
YarnConfiguration.NM_WINDOWS_CONTAINER_MEMORY_LIMIT_ENABLED,
YarnConfiguration.DEFAULT_NM_WINDOWS_CONTAINER_MEMORY_LIMIT_ENABLED)) {
memory = resource.getMemory();
}

if (conf.getBoolean(
YarnConfiguration.NM_WINDOWS_CONTAINER_CPU_LIMIT_ENABLED,
YarnConfiguration.DEFAULT_NM_WINDOWS_CONTAINER_CPU_LIMIT_ENABLED)) {
int containerVCores = resource.getVirtualCores();
int nodeVCores = conf.getInt(YarnConfiguration.NM_VCORES,
YarnConfiguration.DEFAULT_NM_VCORES);
// cap overall usage to the number of cores allocated to YARN
int nodeCpuPercentage = Math
.min(
conf.getInt(
YarnConfiguration.NM_RESOURCE_PERCENTAGE_PHYSICAL_CPU_LIMIT,
YarnConfiguration.DEFAULT_NM_RESOURCE_PERCENTAGE_PHYSICAL_CPU_LIMIT),
100);
nodeCpuPercentage = Math.max(0, nodeCpuPercentage);
if (nodeCpuPercentage == 0) {
String message = "Illegal value for "
+ YarnConfiguration.NM_RESOURCE_PERCENTAGE_PHYSICAL_CPU_LIMIT
+ ". Value cannot be less than or equal to 0.";
throw new IllegalArgumentException(message);
}
float yarnVCores = (nodeCpuPercentage * nodeVCores) / 100.0f;
// CPU should be set to a percentage * 100, e.g. 20% cpu rate limit
// should be set as 20 * 100. The following setting is equal to:
// 100 * (100 * (vcores / Total # of cores allocated to YARN))
cpuRate = Math.min(10000,
(int) ((containerVCores * 10000) / yarnVCores));
}
}
return new String[] { Shell.WINUTILS, "task", "create", "-m",
String.valueOf(memory), "-c", String.valueOf(cpuRate), groupId,
"cmd /c " + command };
} else {
List<String> retCommand = new ArrayList<String>();
if (containerSchedPriorityIsSet) {
retCommand.addAll(Arrays.asList("nice", "-n",
Integer.toString(containerSchedPriorityAdjustment)));
}
retCommand.addAll(Arrays.asList("bash", command));
return retCommand.toArray(new String[retCommand.size()]);
}

}
}

对于 windows(它利用 winutils.exe),它使用 cpu rate对于 Linux 它使用 niceness 作为参数来控制 CPU 优先级

关于hadoop - YARN vcore中的virtual core是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42637631/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com