释放可还原输入的内存

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

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

  1. public void reduce(final Text key, Iterable<MapWritable> inputValues,
  2. final Context context)
  3. {
  4. BufferedWriter bw = new BufferedWriter(
  5. new FileWriterWithEncoding(this.fileName, this.encoding));
  6. for (Iterator<MapWritable> iterator = inputValues.iterator(); iterator.hasNext();)
  7. {
  8. MapWritable mapWritable = iterator.next();
  9. // ----
  10. // Put string contained in mapWritable into a file on disk
  11. // ----
  12. }
  13. bw.close();
  14. // Release the input Iterable instance
  15. inputValues = null; //This doesn't seem to work :'(
  16. BufferedReader br = new BufferedReader(new InputStreamReader(
  17. new FileInputStream(this.fileName), this.encoding));
  18. for (String line; (line = br.readLine()) != null;)
  19. {
  20. // ----
  21. // Then read from the file saved in disk one line at a time
  22. // and process it to build the object B
  23. // ----
  24. }
  25. br.close();
  26. }

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

暂无答案!

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

相关问题