释放可还原输入的内存

91zkwejq  于 2021-06-02  发布在  Hadoop
关注(0)|答案(0)|浏览(260)

我面临一个gc开销问题,因为reducer的输入是巨大的。我没有办法过滤掉任何输入数据,因为iterable参数中的所有条目都是有用的。我尝试在运行此作业的emr集群上增加堆大小,但即使这样也没有帮助。
基本上我的reducer所做的就是获取一个字符串列表并将它们转换成一个对象列表。然后这些物体被组合成一个更大的物体b。我能想到的解决方案是,我可以将整个iterable输入转储到磁盘上,并完全释放iterable对象。然后从磁盘读取转储的字符串,一次读取一个,然后继续构建更大的对象b,中间构建一个对象a,然后在从磁盘获取下一个字符串之前释放a。这样,我将只保留堆中比以前几乎一半的数据。但是,我认为我无法释放iterable输入,因为我仍然得到gc开销。
我尝试的方法如下:

public void reduce(final Text key, Iterable<MapWritable> inputValues,
                   final Context context)
{
    BufferedWriter bw = new BufferedWriter(
                            new FileWriterWithEncoding(this.fileName, this.encoding));
    for (Iterator<MapWritable> iterator = inputValues.iterator(); iterator.hasNext();)
    {
        MapWritable mapWritable = iterator.next();
        // ----
        // Put string contained in mapWritable into a file on disk
        // ----
    }
    bw.close();

    // Release the input Iterable instance
    inputValues = null;  //This doesn't seem to work :'(

    BufferedReader br = new BufferedReader(new InputStreamReader(
                            new FileInputStream(this.fileName), this.encoding));
    for (String line; (line = br.readLine()) != null;)
    {
        // ----
        // Then read from the file saved in disk one line at a time
        // and process it to build the object B
        // ----
    }
    br.close();
}

我的问题是,有没有办法从reducer方法中释放reducer的iterable输入的内存?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题