查看堆外内存_运维_浅蓝浅蓝

CSDN博客 · · 2436 次点击 · · 开始浏览    
这是一个创建于 的文章,其中的信息可能已经有所发展或是发生改变。

一次生产环境高内存

sudo -u admin /java/bin/jmap -histo:live 37 | head -10 | sort -r -k3
在这里插入图片描述
jmap -heap pid
在这里插入图片描述

top

在这里插入图片描述

查看堆外内存

  1. 推荐java visualVM ,安装Buffer Pools来监测
	@Test
    public void test() throws Exception{
        while(true) {
            ByteBuffer byteBuffer = ByteBuffer.allocateDirect(1024 * 1024 * 1);
        }
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

禁用System.gc,直接OOM

-verbose:gc -XX:+PrintGCDetails -XX:MaxDirectMemorySize=50m -XX:+DisableExplicitGC
  • 1

在这里插入图片描述

开启-XX:+ExplicitGCInvokesConcurrent,允许System.gc生效

在这里插入图片描述

  1. sa-jdi.jar
    java -classpath .\sa-jdi.jar sun.jvm.hotspot.HSDB 图形界面 windows无法连接pid

阿尔萨斯

jvm
在这里插入图片描述

手动触发full gc,( sudo -u admin /bin/jmap -histo:live 38 |head -10 )之后
在这里插入图片描述

dashboard
direct 显示40m

在这里插入图片描述

thread
finalizer 8
gc 2
在这里插入图片描述

安装使用

curl -L https://alibaba.github.io/arthas/install.sh | sh
yum install xinetd telnet telnet-server -y
sudo -u admin -EH ./as.sh
  • 1
  • 2
  • 3

greys

安装使用

wget -c http://ompc.oss.aliyuncs.com/greys/release/greys-1.7.6.4-bin.zip
unzip
cd greys
sh ./install-local.sh 安装
开启端口
sudo -u admin ./ga.sh 33
在这里插入图片描述
./greys.sh 开启命令行模式
在这里插入图片描述

输入jvm查看内存情况
在这里插入图片描述

              total        used        free      shared  buff/cache   available
Mem:            15G        8.8G        6.0G        1.0M        700M        6.4G
Swap:            0B          0B          0B
  • 1
  • 2
  • 3

在这里插入图片描述

https://www.jianshu.com/p/c76747997ade
https://www.jianshu.com/p/4e96beb37935

其他命令

quit 退出
shutdown 关闭

perf-tools

/home/admin/busuac/gref/lib

export LD_PRELOAD=/home/admin/busuac/gperf/lib/libtcmalloc.so
export HEAPPROFILE=/home/admin/busuac

./configure --prefix=安装目录

/home/admin/busuac/gperf/lib

堆外内存

在这里插入图片描述
画重点

private static long maxDirectMemory0() {
        long maxDirectMemory = 0;
        try {
            // Try to get from sun.misc.VM.maxDirectMemory() which should be most accurate.
            Class<?> vmClass = Class.forName("sun.misc.VM", true, getSystemClassLoader());
            Method m = vmClass.getDeclaredMethod("maxDirectMemory");
            maxDirectMemory = ((Number) m.invoke(null)).longValue();
        } catch (Throwable ignored) {
            // Ignore
        }

        if (maxDirectMemory > 0) {
            return maxDirectMemory;
        }

        try {
            // Now try to get the JVM option (-XX:MaxDirectMemorySize) and parse it.
            // Note that we are using reflection because Android doesn't have these classes.
            Class<?> mgmtFactoryClass = Class.forName(
                    "java.lang.management.ManagementFactory", true, getSystemClassLoader());
            Class<?> runtimeClass = Class.forName(
                    "java.lang.management.RuntimeMXBean", true, getSystemClassLoader());

            Object runtime = mgmtFactoryClass.getDeclaredMethod("getRuntimeMXBean").invoke(null);

            @SuppressWarnings("unchecked")
            List<String> vmArgs = (List<String>) runtimeClass.getDeclaredMethod("getInputArguments").invoke(runtime);
            for (int i = vmArgs.size() - 1; i >= 0; i --) {
                Matcher m = MAX_DIRECT_MEMORY_SIZE_ARG_PATTERN.matcher(vmArgs.get(i));
                if (!m.matches()) {
                    continue;
                }

                maxDirectMemory = Long.parseLong(m.group(1));
                switch (m.group(2).charAt(0)) {
                    case 'k': case 'K':
                        maxDirectMemory *= 1024;
                        break;
                    case 'm': case 'M':
                        maxDirectMemory *= 1024 * 1024;
                        break;
                    case 'g': case 'G':
                        maxDirectMemory *= 1024 * 1024 * 1024;
                        break;
                }
                break;
            }
        } catch (Throwable ignored) {
            // Ignore
        }

        if (maxDirectMemory <= 0) {
            maxDirectMemory = Runtime.getRuntime().maxMemory();
            logger.debug("maxDirectMemory: {} bytes (maybe)", maxDirectMemory);
        } else {
            logger.debug("maxDirectMemory: {} bytes", maxDirectMemory);
        }

        return maxDirectMemory;
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60

https://segmentfault.com/a/1190000013688744

发布了36 篇原创文章 · 获赞 2 · 访问量 1万+

本文来自:CSDN博客

感谢作者:CSDN博客

查看原文:查看堆外内存_运维_浅蓝浅蓝

2436 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传