定义为实例变量的Hadoop映射器键遇到性能问题

定义为实例变量的Hadoop映射器键遇到性能问题,hadoop,mapreduce,Hadoop,Mapreduce,我有可以处理数百万条记录的文件。我的处理是将记录/行分为好的或坏的。我已经用MapReduce实现了它。 根据每一行的验证,将有两种类型的关键行,好行和坏行 这里的good和bad是键,每一行都是相应键的值 话虽如此,我可以在map任务结束时以下面提到的方式写入上下文: context.write(new Text("good"), new Text ("line content"); else{ context.write(new Text("bad"), new Text ("l

我有可以处理数百万条记录的文件。我的处理是将记录/行分为好的或坏的。我已经用MapReduce实现了它。 根据每一行的验证,将有两种类型的关键行,好行和坏行

这里的good和bad是键,每一行都是相应键的值

话虽如此,我可以在map任务结束时以下面提到的方式写入上下文:

context.write(new Text("good"), new Text ("line content");
else{
      context.write(new Text("bad"), new Text ("line content"));
另一方面,我还可以将键声明为实例变量并写入上下文。对于每个200 MB的2个文件来说,完成映射任务所需的时间几乎是第一个选项的15倍

虽然我相信,第二种选择是更好的编程方式,应该取得更好的效果

有人能告诉我调用context.write时会发生什么吗?由于它是同一个对象,是否需要更多的时间来编写即IO

第二种选择:

public class ValidatorMapper extends Mapper<LongWritable, Text, Text, Text> {

private Text badKey = new Text();
private Text goodKey = new Text();
private Text cleaUpKey = new Text("00");    List<Column> configuredColumns = null;

@Override
protected void setup(Context context) throws IOException, InterruptedException {
    LOGGER.info("ValidatorMapper : setup");

    feedConfig = XMLFeedConfig.getFeed(context.getConfiguration().get(Constants.FEED_CONFIG_STRING));
.....
.....

}

@Override
protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {

    fileName = ((FileSplit) context.getInputSplit()).getPath().getName();
    goodKey.set(fileName);
    badKey.set("bad-record "+fileName);
    ........


    System.out.println("inputColumnSeparator len"+inputColumnSeparator);

    System.out.println("tokensArray len"+tokensArray.length);

    totalRecordNum++;

    StringBuilder sb = new StringBuilder();
    for (Column column : configuredColumns) {
        String tokenValue = null;
        if (column.getOutputIndex() <= tokensArray.length && column.getInputIndex() <= tokensArray.length) {
            tokenValue = tokensArray[column.getInputIndex() - 1];
            if(tokenValue!=null){
                tokenValue = tokenValue.trim();
            }
            LOGGER.info("value"+ value.toString());
            LOGGER.info("column"+ column.getName());
            LOGGER.info("column"+ column.getInputIndex());


            LOGGER.info("tokenValue"+ tokenValue);
            LOGGER.info("tokenValue"+ tokensArray.toString());


            validatedMap = DataTypeValidator.validate(column, tokenValue);
            errorMesg = validatedMap.get(Constants.ERROR_MSG);
            newDateValue = validatedMap.get(Constants.NEW_DATE);
            if (null == errorMesg && null != newDateValue) {
                tokenValue = newDateValue;
            }
        } else {
            if(Constants.DELIMETER.equalsIgnoreCase(dataSeperator))
            {
                errorMesg = Constants.COLUMN_MISMATCH;

            }
        }
        if (errorMesg != null) {
            badFeedCount++;
            context.write(badKey, new Text(value + "bad-line no:" + key));
            break;
        } else {
            sb.append(tokenValue + outputColumnSeparator);
        }
    }
    LOGGER.info("errorMesg = " + errorMesg);
    if (errorMesg == null) {
        String processedValue = sb.substring(0, sb.lastIndexOf(outputColumnSeparator));
        processedRecord.set(processedValue);
        context.write(goodKey, processedRecord);
    }
}
公共类验证映射器扩展映射器{
私有文本badKey=新文本();
私有文本goodKey=新文本();
私有文本cleaUpKey=新文本(“00”);列表配置列=null;
@凌驾
受保护的无效设置(上下文上下文)引发IOException、InterruptedException{
LOGGER.info(“ValidatorMapper:setup”);
feedConfig=XMLFeedConfig.getFeed(context.getConfiguration().get(Constants.FEED\u CONFIG\u STRING));
.....
.....
}
@凌驾
受保护的void映射(LongWritable键、文本值、上下文)引发IOException、InterruptedException{
fileName=((FileSplit)context.getInputSplit()).getPath().getName();
set(文件名);
badKey.set(“坏记录”+文件名);
........
System.out.println(“InputColumnSelector len”+InputColumnSelector);
System.out.println(“tokensArray len”+tokensArray.length);
totalRecordNum++;
StringBuilder sb=新的StringBuilder();
for(列:配置的列){
字符串tokenValue=null;

如果(column.getOutputIndex(),为什么只为一点信息编写一个大文本?只需使用字节可写的0/1()。你能发布第二个选项的完整代码吗?我不认为它慢。它应该性能更好。你的代码中有很多LOGGER.inof和System.out语句,这可能会对性能产生很大影响。你是否在运行测试时将所有这些语句都注释掉了?谢谢,我将对此进行检查。但即使我创建了一个新的密钥e每次我写信给上下文时,这些记录器都会出现。因此,我的实际问题与记录器无关