当前位置: 首页 > news >正文

聊聊jvm的mapped buffer的统计

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

示例

private void writeDirectBuffer() {// 分配一个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());
}private void writeMappedBuffer() throws IOException {RandomAccessFile file = new RandomAccessFile("/tmp/test.txt", "rw");FileChannel channel = file.getChannel();MappedByteBuffer buffer = channel.map(FileChannel.MapMode.READ_WRITE, 0, 128 * 1024 * 1024); // 映射128MB的空间// 随机写入数据for (int i = 0; i < buffer.capacity(); i++) {buffer.put((byte) i);}
}

jvm.buffer.memory.used

http://localhost:8080/actuator/metrics/jvm.buffer.memory.used

{"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": 402685952}],"availableTags": [{"tag": "id","values": ["direct","mapped"]}]
}

jvm.buffer.memory.used分了direct和mapped两大类,一共用了384MB

mapped

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

{"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": 134217728}],"availableTags": []
}

可以看到这里mapped用了128MB

direct

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

{"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": 268500992}],"availableTags": []
}

可以看到这里direct用了256MB

Native Memory Tracking

开启

java -XX:+UnlockDiagnosticVMOptions -XX:NativeMemoryTracking=summary -jar target/app.jar

监控

jcmd 2315 VM.native_memory summary scale=MB
2315:Native Memory Tracking:Total: reserved=5882MB, committed=1100MB
-                 Java Heap (reserved=4096MB, committed=577MB)(mmap: reserved=4096MB, committed=577MB)-                     Class (reserved=1066MB, committed=46MB)(classes #7035)(malloc=10MB #10793)(mmap: reserved=1056MB, committed=37MB)-                    Thread (reserved=36MB, committed=36MB)(thread #37)(stack: reserved=36MB, committed=36MB)-                      Code (reserved=246MB, committed=16MB)(malloc=2MB #3971)(mmap: reserved=244MB, committed=13MB)-                        GC (reserved=160MB, committed=148MB)(malloc=10MB #219)(mmap: reserved=150MB, committed=138MB)-                  Internal (reserved=266MB, committed=266MB)(malloc=266MB #10067)-                    Symbol (reserved=9MB, committed=9MB)(malloc=8MB #74334)(arena=2MB #1)-    Native Memory Tracking (reserved=2MB, committed=2MB)(tracking overhead=2MB)

NTM的Internal包含了direct buffer的统计,不包含mapped buffer的占用,而BufferPoolMXBean包含了direct和mapped。
另外通过调用System.loadLibrary()加载的共享库分配的内存NTM没办法追踪到,MXBean貌似也没办法统计到。

小结

  • 聊聊jvm的direct buffer统计
  • Memory Types in JVM
  • Native Memory Tracking in JVM
  • How to monitor JVM native memory usage by enabling native memory tracking
  • Troubleshooting Problems With Native (Off-Heap) Memory in Java Applications
  • Can a Java Application Use More Memory Than the Heap Size?
  • java-non-heap-memory-analyzes
http://www.lryc.cn/news/275550.html

相关文章:

  • matrix-breakout-2-morpheus 靶场 练习思路
  • 【Flutter 开发实战】Dart 基础篇:从了解背景开始
  • 西电期末1017.有序序列插值
  • day10 用栈实现队列 用队列实现栈
  • 解决跨域问题(SpringBoot)
  • LeetCode——2487. 从链表中移除节点
  • 云原生和Kubernetes如何简化应用程序开发
  • 点云从入门到精通技术详解100篇-基于深度学习的室内场景三维点云语义分割(续)
  • RabbitMQ消息可靠性保证机制3--消费端ACK机制
  • Copilot在Pycharm的应用和示例
  • 搜维尔科技:【简报】第九届元宇宙数字人设计大赛,报名已经进入白热化阶段!
  • 性能检测自动化(含内存泄露检测)
  • iec104和iec61850
  • redis 面试问题 (更新中 ing)
  • 力扣(leetcode)第389题找不同(Python)
  • Linux_源码编译安装LAMP
  • 静态网页设计——清雅古筝网(HTML+CSS+JavaScript)
  • 实战Flink Java api消费kafka实时数据落盘HDFS
  • 爬虫与反爬-localStorage指纹(某易某盾滑块指纹检测)(Hook案例)
  • 聊一聊 webpack 和 vite 的开发服务代理的问题
  • 【鸿蒙4.0】安装DevEcoStudio
  • [概率论]四小时不挂猴博士
  • 算法通关村第二十关-黄金挑战图的常见算法
  • 服务器内存不足怎么办?会有什么影响?
  • GPT实战系列-简单聊聊LangChain
  • 【读书笔记】《白帽子讲web安全》浏览器安全
  • 海外服务器2核2G/4G/8G和4核8G配置16M公网带宽优惠价格表
  • Linux 编译安装 Nginx
  • Oracle文件自动“减肥”记
  • 【csharp】抽象类与接口有哪些不同?什么时候应该使用抽象类?