数据倾斜现象
数据频率倾斜—-某一个区域的数据量要远远大于其他区域
数据大小倾斜—-部分记录的大小远远大于平均值
如何收集倾斜数据
在reduce方法中加入记录map输出键的详细情况的功能
public static final String MAX_VALUES = "skew.maxvalues";private int maxValueThreshold;@Overridepublic void configure(JobConf job) {//设置个最大值maxValueThreshold = job.getInt(MAX_VALUES, 100);}@Overrideprotected void reduce(Text key, Iterator<Text> values, OutputCollector<Text, Text> output, Reporter reporter) throws IOException, InterruptedException {int i = 0;while(values.hasNext()) {values.next();//迭代的时候把这个加加i++;}//如果值大于自己设置的最大值,就把他们记录下来if (++i > maxValueThreshold) {log.info("Received"+ i + " values for key " + key);}}
