一次生产环境高内存
sudo -u admin /java/bin/jmap -histo:live 37 | head -10 | sort -r -k3
jmap -heap pid
top
查看堆外内存
- 推荐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生效
- 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