以编程方式限制 YARN 容器

Limit YARN containers programmatically

我在 hadoop 集群中有 10 个节点,内存为 32GB,一个节点内存为 64GB。

对于这 10 个节点,节点限制 yarn.nodemanager.resource.memory-mb 设置为 26GB,64GB 节点设置为 52GB(有一些作业需要 50GB 的单个减速器,它们 运行 在这个节点上)

问题是,当我 运行 基本作业需要 8GB 映射器时,32GB 节点并行生成 3 个映射器 (26 / 8 = 3),而 64GB 节点生成 6 个映射器。由于 CPU 负载,此节点通常最后完成。

我想以编程方式限制作业容器资源,例如将大多数作业的容器限制设置为 26GB。如何做呢?

你必须这样设置配置。试试这个

// create a configuration
Configuration conf = new Configuration();
// create a new job based on the configuration
Job job = new Job(conf);
// here you have to put your mapper class
job.setMapperClass(Mapper.class);
// here you have to put your reducer class
job.setReducerClass(Reducer.class);
// here you have to set the jar which is containing your 
// map/reduce class, so you can use the mapper class
job.setJarByClass(Mapper.class);
// key/value of your reducer output
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class);
// this is setting the format of your input, can be TextInputFormat
job.setInputFormatClass(SequenceFileInputFormat.class);
// same with output
job.setOutputFormatClass(TextOutputFormat.class);
// here you can set the path of your input
SequenceFileInputFormat.addInputPath(job, new Path("files/toMap/"));
// this deletes possible output paths to prevent job failures
FileSystem fs = FileSystem.get(conf);
Path out = new Path("files/out/processed/");
fs.delete(out, true);
// finally set the empty out path
TextOutputFormat.setOutputPath(job, out);

// this waits until the job completes and prints debug out to STDOUT or whatever
// has been configured in your log4j properties.
job.waitForCompletion(true); 

对于YARN,需要设置以下配置。

// this should be like defined in your yarn-site.xml
conf.set("yarn.resourcemanager.address", "yarn-manager.com:50001"); 

//For set to 26GB
conf.set("yarn.nodemanager.resource.memory-mb", "26624"); 


// framework is now "yarn", should be defined like this in mapred-site.xm
conf.set("mapreduce.framework.name", "yarn");

// like defined in hdfs-site.xml
conf.set("fs.default.name", "hdfs://namenode.com:9000");

首先,yarn.nodemanager.resource.memory-mb(内存)、yarn.nodemanager.resource.cpu-vcores(vcore)是 Nodemanager daemon/service 配置属性,不能在 YARN 客户端应用程序中被覆盖。如果更改这些配置属性,则需要重新启动 nodemanager 服务。

由于 CPU 是你的瓶颈,我的建议是将 YARN 调度策略更改为 Fairscheduler with DRF (Dominant Resource Fairness) 调度策略集群级别,这样您就可以根据内存和 cpu 核心灵活地指定应用程序容器的大小。 运行 个应用程序容器 (mapper/reducer/AM/tasks) 的数量将基于您定义的可用 vcores

可以在公平调度程序 queue/pool 级别设置调度策略。

schedulingPolicy:设置任意队列的调度策略。允许的值为“fifo”/“fair”/“drf”

有关详细信息,请参阅 this apache doc -

使用 DRF 调度策略创建新的公平调度程序 queue/pool 后,两个内存都可以 cpu 核心可以在程序中进行如下设置。

配置 conf = new Configuration();

如何在 mapreduce 应用程序中定义容器大小。

Configuration conf = new Configuration();

conf.set("mapreduce.map.memory.mb","4096");
conf.set(mapreduce.reduce.memory.mb","4096");

conf.set(mapreduce.map.cpu.vcores","1");
conf.set(mapreduce.reduce.cpu.vcores","1");

参考 - https://hadoop.apache.org/docs/r2.7.2/hadoop-mapreduce-client/hadoop-mapreduce-client-core/mapred-default.xml

mapper/reducer 的 cpu.vcores 分配的默认值为 1,如果它是 cpu 密集型应用程序,您可以增加此值。 请记住,如果增加此值,并行的 mapper/reducer 个任务 运行 的数量也会减少。