查看堆外内存

一次生产环境高内存

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);
        }
    }

禁用System.gc,直接OOM

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

在这里插入图片描述

开启-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

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

在这里插入图片描述

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;
    }

https://segmentfault.com/a/1190000013688744

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值