java - java heap dump 显示的保留堆内存比预期的要少
问题描述
我正在检查我的应用程序的堆转储。该应用程序有一个java.util.concurrent.ConcurrentHashMap
where 键类型是java.lang.String
,值是一个带有byte[]
字段的用户定义类。
我添加了 16000 个键,每个键 30 个字符,值的字节数组为 3000 字节。所以我预计并发 hashmap 的总体保留堆大小为 48MB (16000 * 3000)。
但是堆转储中的值是 24MB。当我进一步检查时,我发现有很多条目如下所示。这些条目的HashMap Node 的retained size 远小于key 和value 的retained size 之和。
如何理解这种差异?
Class Name | Shallow Heap | Retained Heap
----------------------------------------------------------------------------------------------------------------------
[5490] java.util.concurrent.ConcurrentHashMap$Node @ 0x6c6a23910 | 32 | 136
|- <class> class java.util.concurrent.ConcurrentHashMap$Node @ 0x6c71bc320 System Class| 0 | 0
|- key java.lang.String @ 0x6c6a23930 /data-node-3-10/parent2/child2 | 24 | 104
|- val org.apache.zookeeper.server.DataNode @ 0x6c6a23998 | 32 | 3,304
----------------------------------------------------------------------------------------------------------------------
PS:我手头的任务是找到系统配置和内存使用之间的关联。
编辑:对于许多其他条目,值如下。HashMap 节点的保留大小(3160)包含节点的键(128)+值(3000)的保留大小。但是对于某些条目(例如,如上所示),对于 key 和 value 的保留大小分别为 104 和 3304 的节点,它似乎不正确(136)。
Class Name | Shallow Heap | Retained Heap
----------------------------------------------------------------------------------------------------------------------
[9706] java.util.concurrent.ConcurrentHashMap$Node @ 0x6c6a1ab98 | 32 | 3,160
|- <class> class java.util.concurrent.ConcurrentHashMap$Node @ 0x6c71bc320 System Class| 0 | 0
|- key java.lang.String @ 0x6c6a1abb8 /data-node-0-10/parent1/child2/grandchild1 | 24 | 128
|- val org.apache.zookeeper.server.DataNode @ 0x6c6a1ac38 | 32 | 3,000
----------------------------------------------------------------------------------------------------------------------
解决方案
推荐阅读
- user-interface - HiveMQ 中 Web UI 的 SSL/TLS
- docker - Hadoop namenode 无法识别 docker 中的数据节点
- laravel - Vagrant Share - Laravel Homestead,Ubuntu
- android-studio - Android Studio 没有按属性对齐我的代码
- java - Jooq Loggerlistener 查询执行时间不一致
- azure-cosmosdb - 在 ARM 模板中获取 CosmosDb 主连接字符串
- windows-10 - Windows 10 上的“bash:fork:重试:资源暂时不可用”错误
- jenkins - 如何让通用 Webhook 触发器插件与 Jenkins 中的多分支管道一起使用?
- javascript - 在 Javascript 中转换 UTC 日期的替代方法?
- c# - 如何在 C# 中展平嵌套元组?