前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >聊聊jvm的direct buffer统计

聊聊jvm的direct buffer统计

作者头像
code4it
发布2024-01-19 16:29:46
1000
发布2024-01-19 16:29:46
举报
文章被收录于专栏:码匠的流水账码匠的流水账

本文主要研究一下jvm的direct buffer统计

spring boot metrics

jvm.memory.used

代码语言:javascript
复制
{
    "name": "jvm.memory.used",
    "description": "The amount of used memory",
    "baseUnit": "bytes",
    "measurements": [
        {
            "statistic": "VALUE",
            "value": 137868592
        }
    ],
    "availableTags": [
        {
            "tag": "area",
            "values": [
                "heap",
                "nonheap"
            ]
        },
        {
            "tag": "id",
            "values": [
                "Compressed Class Space",
                "PS Survivor Space",
                "PS Old Gen",
                "Metaspace",
                "PS Eden Space",
                "Code Cache"
            ]
        }
    ]
}

jvm.memory.used包括heap和nonheap两大类

heap

http://localhost:8080/actuator/metrics/jvm.memory.used?tag=area:heap

代码语言:javascript
复制
{
    "name": "jvm.memory.used",
    "description": "The amount of used memory",
    "baseUnit": "bytes",
    "measurements": [
        {
            "statistic": "VALUE",
            "value": 84724536
        }
    ],
    "availableTags": [
        {
            "tag": "id",
            "values": [
                "PS Eden Space",
                "PS Survivor Space",
                "PS Old Gen"
            ]
        }
    ]
}

heap的话根据具体的垃圾收集器类型有不同的区分

nonheap

http://localhost:8080/actuator/metrics/jvm.memory.used?tag=area:nonheap

代码语言:javascript
复制
{
    "name": "jvm.memory.used",
    "description": "The amount of used memory",
    "baseUnit": "bytes",
    "measurements": [
        {
            "statistic": "VALUE",
            "value": 54874872
        }
    ],
    "availableTags": [
        {
            "tag": "id",
            "values": [
                "Metaspace",
                "Compressed Class Space",
                "Code Cache"
            ]
        }
    ]
}

nonheap这里包括3个,分别是Metaspace、Compressed Class Space、Code Cache

jvm.buffer.memory.used

http://localhost:8080/actuator/metrics/jvm.buffer.memory.used?tag=id:direct

代码语言:javascript
复制
{
    "name": "jvm.buffer.memory.used",
    "description": "An estimate of the memory that the Java virtual machine is using for this buffer pool",
    "baseUnit": "bytes",
    "measurements": [
        {
            "statistic": "VALUE",
            "value": 81920
        }
    ],
    "availableTags": [
        {
            "tag": "id",
            "values": [
                "direct",
                "mapped"
            ]
        }
    ]
}

jvm.buffer.memory.used包含了direct、mapped两大类

direct

http://localhost:8080/actuator/metrics/jvm.buffer.memory.used?tag=id:direct

代码语言:javascript
复制
{
    "name": "jvm.buffer.memory.used",
    "description": "An estimate of the memory that the Java virtual machine is using for this buffer pool",
    "baseUnit": "bytes",
    "measurements": [
        {
            "statistic": "VALUE",
            "value": 81920
        }
    ],
    "availableTags": []
}

mapped

http://localhost:8080/actuator/metrics/jvm.buffer.memory.used?tag=id:mapped

代码语言:javascript
复制
{
    "name": "jvm.buffer.memory.used",
    "description": "An estimate of the memory that the Java virtual machine is using for this buffer pool",
    "baseUnit": "bytes",
    "measurements": [
        {
            "statistic": "VALUE",
            "value": 0
        }
    ],
    "availableTags": []
}

jvm.buffer.count

http://localhost:8080/actuator/metrics/jvm.buffer.count

代码语言:javascript
复制
{
    "name": "jvm.buffer.count",
    "description": "An estimate of the number of buffers in the pool",
    "baseUnit": "buffers",
    "measurements": [
        {
            "statistic": "VALUE",
            "value": 10
        }
    ],
    "availableTags": [
        {
            "tag": "id",
            "values": [
                "direct",
                "mapped"
            ]
        }
    ]
}

jvm.buffer.count分direct和mapped两大类

direct

http://localhost:8080/actuator/metrics/jvm.buffer.count?tag=id:direct

代码语言:javascript
复制
{
    "name": "jvm.buffer.count",
    "description": "An estimate of the number of buffers in the pool",
    "baseUnit": "buffers",
    "measurements": [
        {
            "statistic": "VALUE",
            "value": 10
        }
    ],
    "availableTags": []
}

mapped

http://localhost:8080/actuator/metrics/jvm.buffer.count?tag=id:mapped

代码语言:javascript
复制
{
    "name": "jvm.buffer.count",
    "description": "An estimate of the number of buffers in the pool",
    "baseUnit": "buffers",
    "measurements": [
        {
            "statistic": "VALUE",
            "value": 0
        }
    ],
    "availableTags": []
}

jvm.buffer.total.capacity

http://localhost:8080/actuator/metrics/jvm.buffer.total.capacity

代码语言:javascript
复制
{
    "name": "jvm.buffer.total.capacity",
    "description": "An estimate of the total capacity of the buffers in this pool",
    "baseUnit": "bytes",
    "measurements": [
        {
            "statistic": "VALUE",
            "value": 81920
        }
    ],
    "availableTags": [
        {
            "tag": "id",
            "values": [
                "direct",
                "mapped"
            ]
        }
    ]
}

jvm.buffer.total.capacity分direct和mapped两大类

direct

http://localhost:8080/actuator/metrics/jvm.buffer.total.capacity?tag=id:direct

代码语言:javascript
复制
{
    "name": "jvm.buffer.total.capacity",
    "description": "An estimate of the total capacity of the buffers in this pool",
    "baseUnit": "bytes",
    "measurements": [
        {
            "statistic": "VALUE",
            "value": 81920
        }
    ],
    "availableTags": []
}

mapped

http://localhost:8080/actuator/metrics/jvm.buffer.total.capacity?tag=id:mapped

代码语言:javascript
复制
{
    "name": "jvm.buffer.total.capacity",
    "description": "An estimate of the total capacity of the buffers in this pool",
    "baseUnit": "bytes",
    "measurements": [
        {
            "statistic": "VALUE",
            "value": 0
        }
    ],
    "availableTags": []
}

Native Memory Tracking

summary

代码语言:javascript
复制
jcmd 6878 VM.native_memory summary scale=MB
6878:

Native Memory Tracking:

Total: reserved=5625MB, committed=844MB
-                 Java Heap (reserved=4096MB, committed=577MB)
                            (mmap: reserved=4096MB, committed=577MB)

-                     Class (reserved=1066MB, committed=46MB)
                            (classes #7027)
                            (malloc=10MB #10535)
                            (mmap: reserved=1056MB, committed=37MB)

-                    Thread (reserved=36MB, committed=36MB)
                            (thread #37)
                            (stack: reserved=36MB, committed=36MB)

-                      Code (reserved=246MB, committed=15MB)
                            (malloc=2MB #3834)
                            (mmap: reserved=244MB, committed=12MB)

-                        GC (reserved=160MB, committed=148MB)
                            (malloc=10MB #220)
                            (mmap: reserved=150MB, committed=138MB)

-                  Internal (reserved=10MB, committed=10MB)
                            (malloc=10MB #10055)

-                    Symbol (reserved=9MB, committed=9MB)
                            (malloc=8MB #74319)
                            (arena=2MB #1)

-    Native Memory Tracking (reserved=2MB, committed=2MB)
                            (tracking overhead=2MB)

其中Internal部分包含了jvm中使用的directBuffer的大小

示例

代码语言:javascript
复制
    public void run(String... args) throws Exception {
        // 分配一个256MB的直接缓冲区
        ByteBuffer buffer = ByteBuffer.allocateDirect(256 * 1024 * 1024);

        // 填充数据
        Random random = new Random();
        while (buffer.remaining() >= 4) {
            buffer.putInt(random.nextInt());
        }

        System.out.println("Allocated direct buffer with capacity " + buffer.capacity());
    }

VM.native_memory

代码语言:javascript
复制
jcmd 8077 VM.native_memory summary scale=MB
8077:

Native Memory Tracking:

Total: reserved=5881MB, committed=1099MB
-                 Java Heap (reserved=4096MB, committed=576MB)
                            (mmap: reserved=4096MB, committed=576MB)

-                     Class (reserved=1066MB, committed=46MB)
                            (classes #7028)
                            (malloc=10MB #10794)
                            (mmap: reserved=1056MB, committed=37MB)

-                    Thread (reserved=36MB, committed=36MB)
                            (thread #37)
                            (stack: reserved=36MB, committed=36MB)

-                      Code (reserved=246MB, committed=16MB)
                            (malloc=2MB #3889)
                            (mmap: reserved=244MB, committed=13MB)

-                        GC (reserved=160MB, committed=148MB)
                            (malloc=10MB #220)
                            (mmap: reserved=150MB, committed=138MB)

-                  Internal (reserved=266MB, committed=266MB)
                            (malloc=266MB #10055)

-                    Symbol (reserved=9MB, committed=9MB)
                            (malloc=8MB #74324)
                            (arena=2MB #1)

-    Native Memory Tracking (reserved=2MB, committed=2MB)
                            (tracking overhead=2MB)

可以看到Internal部分由之前的10MB增大到了266MB

jvm.buffer.memory.used

http://localhost:8080/actuator/metrics/jvm.buffer.memory.used?tag=id:direct

代码语言:javascript
复制
{
    "name": "jvm.buffer.memory.used",
    "description": "An estimate of the memory that the Java virtual machine is using for this buffer pool",
    "baseUnit": "bytes",
    "measurements": [
        {
            "statistic": "VALUE",
            "value": 268476416
        }
    ],
    "availableTags": []
}

可以看到jvm.buffer.memory.used的direct部分也变大了

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2024-01-07,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 码匠的流水账 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 本文主要研究一下jvm的direct buffer统计
  • spring boot metrics
    • jvm.memory.used
      • heap
      • nonheap
    • jvm.buffer.memory.used
      • direct
      • mapped
    • jvm.buffer.count
      • direct
      • mapped
    • jvm.buffer.total.capacity
      • direct
      • mapped
  • Native Memory Tracking
    • summary
      • 示例
        • VM.native_memory
          • jvm.buffer.memory.used
          领券
          问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档