你好,游客 登录 注册 搜索
背景:
阅读新闻

利用Map Reduce 过滤大数据的解决方案

[日期:2013-03-21] 来源:Linux社区  作者:kntao [字体:大 中 小]

跑了一遍才发行,reduce并没有输出结果。google了一下才知道iterator并不能迭代2次,其中的原因reduce阶段不是把所以的map的输出缓冲到内存中的,其实想想就应该知道。如果都缓存到内存中,数据大很容易内存溢出。

public boolean nextKeyValue() throws IOException, InterruptedException 
    { 
        if (!hasMore) 
        { 
              key = null; 
              value = null; 
              return false; 
        } 
        firstValue = !nextKeyIsSame; 
        DataInputBuffer next = input.getKey(); 
        currentRawKey.set(next.getData(), next.getPosition(), next.getLength() 
                  - next.getPosition()); 
        buffer.reset(currentRawKey.getBytes(), 0, currentRawKey.getLength()); 
        key = keyDeserializer.deserialize(key); 
        next = input.getValue(); 
        buffer.reset(next.getData(), next.getPosition(), next.getLength()); 
        value = valueDeserializer.deserialize(value); 
        hasMore = input.next(); 
        if (hasMore) 
        { 
              next = input.getKey(); 
              nextKeyIsSame = comparator.compare(currentRawKey.getBytes(), 0, 
                        currentRawKey.getLength(), next.getData(), next 
                                  .getPosition(), next.getLength() 
                                  - next.getPosition()) == 0; 
        } 
        else 
        { 
              nextKeyIsSame = false; 
        } 
        inputValueCounter.increment(1L); 
        return true; 
    } 

在想想,想减少reduce阶段的输入,在map阶段减少输出。于是就有了在map阶段把uid分成奇数,偶数分别作为reduce的输出,去跑job。所以要尽量减少reduce的输入,可以通过拆分map输出的方法。

更多Hadoop相关信息见Hadoop 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=13

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款