我正在使用 lru 缓存,它对内存使用大小有限制。 lru缓存包括两种数据结构:哈希图和链表。哈希映射保存缓存对象,链表保存缓存对象访问顺序的记录。为了确定java对象内存使用情况,我使用了一个开源工具——Classmexer agent
这是一个简单的 Java 检测代理,位于 http://www.javamex.com/classmexer/。
我尝试了另一个名为 SizeOf 的工具,网址为 http://sizeof.sourceforge.net/。
问题是性能非常昂贵。测量物体尺寸的一次操作的时间成本约为 1.3 秒,非常非常慢。这会使缓存的好处为零。
还有其他解决方案可以测量 java 对象存活时的内存大小吗?
谢谢。
I am using a lru cache which has limit on memory usage size. The lru cache include two data structures: a hashmap and a linked list. The hash map holds the cache objects and the linked list keeps records of cache object access order. In order to determine java object memory usage, I use an open source tool -- Classmexer agent
which is a simple Java instrumentation agent at http://www.javamex.com/classmexer/.
I try another tool named SizeOf at http://sizeof.sourceforge.net/.
The problem is the performance very expensive. The time cost for one operation for measuring object size is around 1.3 sec which is very very slow. This can make the benefits of caching to be zero.
Is there any other solution to measuring a java object memory size when it is alive?
Thanks.
发布评论
评论(3)
获取准确的字节值将会很昂贵,因为它需要使用反射来获取嵌套大小,但这是可以做到的。
在 Java 中,什么是确定对象大小的最佳方法?
http://docs.oracle.com/javase/7/docs/api/java/lang/instrument/Instrumentation.html
Getting an accurate, to the byte value will be expensive as it needs to use reflection to get a nested size, but it can be done.
In Java, what is the best way to determine the size of an object?
http://docs.oracle.com/javase/7/docs/api/java/lang/instrument/Instrumentation.html
看看这个:如何计算Java数组的内存使用量也许它有帮助你在分析中。
Look at this: How to calculate the memory usage of a Java array Maybe it helps you in the analysis.
既然您已经有了一个可以做到这一点的工具...事实上,在 Java 中没有快速的方法来做到这一点。
Since you already have a tool that does it...the reality is that there's no fast way to do this in Java.