mapred.map.tasks(无效)直接设置任务个数无效
影响因子
input_file_num:文件数量
input_file_size:文件大小
mapred.max.split.size(default 265M)
mapred.min.split.size(default 1B)
切割算法(TextInputFormat切分)
splitSize=max[minSize,min(maxSize,blockSize)]
map个数并不是越大越好,或者越小越好。
因为map启动、初始化大概需要1~5秒时间
当然map数也不是越小越好,一般mapred.max.split.size默认256M就比较好。
如果涉及到cube、rollup、cpu密集型作业,可适当降低mapred.max.split.size的大小,增大map数
mapred.reduce.tasks=#number(可手工设置)
影响因子
hive.exec.reducers.max (hive设置的最大可用reducer)
hive.exec.reducers.bytes.per.reducer (hive默认每1G文件分配一个reduce)
分配算法
num_reduce_tasks=min[maxReucers,input.size/perReducer]
reduce最大参数设置建议计算公式
(集群总Reduce个槽位个数*1.5)/(执行中的查询平均数)
hive是按照输入数据量大小确定reduce个数
默认hive.exec.reducers.bytes.per.reducer=1000,000,000 1G(一个reduce处理1G~10G之间数据量,比较合适)
也就是说你如果有20G的数据,将会启动20个reduce,同时会与1、设置的最大maxReducers做比较
if (totalInputFileSize != inputSummary.getLength()) {
LOG.info("BytesPerReducer=" + bytesPerReducer + " maxReducers="
+ maxReducers + " estimated totalInputFileSize=" + totalInputFileSize);
} else {
LOG.info("BytesPerReducer=" + bytesPerReducer + " maxReducers="
+ maxReducers + " totalInputFileSize=" + totalInputFileSize);
}
int reducers = (int) ((totalInputFileSize + bytesPerReducer - 1) / bytesPerReducer);
reducers = Math.max(1, reducers);
reducers = Math.min(maxReducers, reducers);
另外如果你开启了hive.exec.infer.bucket.sort.num.buckets.power.two参数,hive会设置reduce个数为2的N次方,
比如原本27个reduece,hive就会开启32个。有利有弊,具体优缺点可以参考hive/conf/hive-default.xml.template
// If this map reduce job writes final data to a table and bucketing is being inferred,
// and the user has configured Hive to do this, make sure the number of reducers is a
// power of two
if (conf.getBoolVar(HiveConf.ConfVars.HIVE_INFER_BUCKET_SORT_NUM_BUCKETS_POWER_TWO) &&
work.isFinalMapRed() && !work.getBucketedColsByDirectory().isEmpty()) {
int reducersLog = (int)(Math.log(reducers) / Math.log(2)) + 1;
int reducersPowerTwo = (int)Math.pow(2, reducersLog);
if (reducersPowerTwo / 2 == reducers) {
return reducers;
} else if (reducersPowerTwo > maxReducers) {
reducers = reducersPowerTwo / 2;
} else {
// Otherwise use the smallest power of two greater than the original number of reducers
reducers = reducersPowerTwo;
}
}
不过有些情况下,查询的map阶段会产生比实际输入数据量要多得多的数据。如果map阶段产生的数据量非常多,那么根据输入的数据量大小来确定的reduce个数就显得有些少了,
比如数据魔方cube、rollup之类。同样地,map阶段也可能过滤掉输入数据集中的很大一部分数据,这个时候就只需要少量的reduce就满足计算,比如wordcount、pv之类的。