如何查看hadoop的堆使用?

xggvc2p6  于 2021-06-04  发布在  Hadoop
关注(0)|答案(1)|浏览(341)

我正在做一个学校作业来分析hadoop中heap的用法。它包括运行两个版本的mapreduce程序来计算论坛评论长度的中位数:第一个版本是“记忆无意识”,reduce程序在内存中处理一个包含每个评论长度的列表;第二种是“内存意识”,reducer使用非常高效的内存数据结构来处理数据。
其目的是使用这两个程序来处理不同大小的数据,并观察第一个程序的内存使用情况如何加快(直到最终耗尽内存)。
我的问题是:如何获得hadoop或reduce任务的堆使用率?
我认为计数器“total committed heap usage(bytes)”会包含这些数据,但我发现两个版本的程序返回的值几乎相同。
关于程序的正确性,“记忆无意识”一个用大量的输入耗尽内存并失败,而另一个没有,并且能够完成。
提前谢谢

wfypjpf4

wfypjpf41#

我不知道您使用的是什么有内存意识的数据结构(如果您给出哪一种可能会有所帮助),但大多数内存中的数据结构都使用虚拟内存,这意味着数据结构大小会根据策略在一定程度上增加,额外的数据元素将转储到虚拟内存中。因此,我们不会导致内存不足错误。但万一记忆无意识不能做到这一点。在这两种情况下,数据结构的大小将保持不变,这就是为什么会得到相同的大小。要通过reducer获得真正的内存使用率,您可以通过以下方式获得:
Java1.5增加的新特性是 Instrumentation 用于获取对象内存使用情况的接口( getObjectSize ). 关于它的好文章:链接

/* Returns the amount of free memory in the Java Virtual Machine. Calling the gc method may result in increasing the value returned by freeMemory.*/
long freeMemory = Runtime.getRuntime().freeMemory()

/* Returns the maximum amount of memory that the Java virtual machine will attempt to use. If there is no inherent limit then the value Long.MAX_VALUE will be returned. */
long maximumMemory = Runtime.getRuntime().maxMemory();

/* Returns the total amount of memory in the Java virtual machine. The value returned by this method may vary over time, depending on the host environment.
Note that the amount of memory required to hold an object of any given type may be implementation-dependent. */
long totalMemory = Runtime.getRuntime().totalMemory()

相关问题