reducer总报出outofMemory的错误

33 views
Skip to first unread message

张雨晴

unread,
Jul 19, 2014, 12:10:46 PM7/19/14
to cs40...@googlegroups.com
我的程序中mapper运行正常,但reducer总是运行的特别慢而且每次都报出Error: java.lang.OutOfMemoryError: Java heap space
reducer函数实现如下:

public static class LineIndexerReducer extends Reducer<Text, Text, Text, Text> {
private String postings = new String();
private Text result = new Text();
public void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
for (Text val : values) {
    postings += '^' + val.toString();
}
                result.set(postings);
context.write(key, result);
}
}

杨博文

unread,
Jul 19, 2014, 3:21:09 PM7/19/14
to cs40...@googlegroups.com
conf.set("mapred.child.java.opts","-Xmx某大小m");
将某大小改大些试试

在 2014年7月20日星期日UTC+8上午12时10分46秒,张雨晴写道:

张雨晴

unread,
Jul 20, 2014, 12:30:43 AM7/20/14
to cs40...@googlegroups.com
谢谢,改到1000m还是特别慢,有时运行不了……我觉得是不是程序有问题?
map函数是:
public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
StringTokenizer itr = new StringTokenizer(value.toString(), "\n");
while (itr.hasMoreTokens()) {
filename = ((FileSplit) context.getInputSplit()).getPath().getName();
term.set(itr.nextToken());
       offset.set(((LongWritable) key).get());
       if(key.toString() == "cipher") 
        result.set(filename + '@' + offset.toString() + '@' + value.toString());  
       else
        result.set(filename + '@' + offset.toString());
       context.write(term, result);
}
}



在 2014年7月20日星期日UTC+8上午3时21分09秒,杨博文写道:

杨博文

unread,
Jul 20, 2014, 12:59:30 AM7/20/14
to cs40...@googlegroups.com
呃……默认情况下TextInputFormat是一次读取一行的,也就是说value.toString()就已经是一行内容,不必用\n来Tokenize
还是说你改写了个继承FileInputFormat的类?

在 2014年7月20日星期日UTC+8下午12时30分43秒,张雨晴写道:

张雨晴

unread,
Jul 20, 2014, 1:06:09 AM7/20/14
to cs40...@googlegroups.com
哦哦抱歉……那是原来的代码,把“\n”去掉也不解决问题

在 2014年7月20日星期日UTC+8下午12时59分30秒,杨博文写道:

Sui Li

unread,
Jul 20, 2014, 1:20:20 AM7/20/14
to cs40...@googlegroups.com
一大串String的连接改成用StringBuffer或StringBuilder,
String的加号是很慢的


--
You received this message because you are subscribed to the Google Groups "cs402pku" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cs402pku+u...@googlegroups.com.
To post to this group, send email to cs40...@googlegroups.com.
Visit this group at http://groups.google.com/group/cs402pku.
For more options, visit https://groups.google.com/d/optout.



--
李睢
SEWM
CS
PKU

Sui Li

unread,
Jul 20, 2014, 1:23:26 AM7/20/14
to cs40...@googlegroups.com
不对, 好像是程序有问题,
posting没有清空, 不同的key也会累加到同一个posting上

张雨晴

unread,
Jul 20, 2014, 2:12:30 AM7/20/14
to cs40...@googlegroups.com
果然!问题解决了,谢谢O(∩_∩)O

在 2014年7月20日星期日UTC+8下午1时23分26秒,Sui Li写道:

杨博文

unread,
Jul 20, 2014, 2:37:08 AM7/20/14
to cs40...@googlegroups.com
啊对了这个代码确实posting越弄越大……

在 2014年7月20日星期日UTC+8下午1时23分26秒,Sui Li写道:
Reply all
Reply to author
Forward
0 new messages