jvm虚拟机调优实战

ops/2024/10/21 1:12:09/
  1. 使用命令 jps查看进程
  2. 使用jstat gc -1 5000查看内存占用和回收情况

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

正式测试 是否跑job区别。大量的job,部分用户点击的热数据 ,不同时刻在跑 600-700对比 200 多了400-500m,代码原数据(不占用堆区)占了300m,所以 堆空间=老年代(900)+700+7 约等于 1500-1600m。加上本地区(主要是栈内存(堆的对象引用指针) gc root+程序及计数器等小空间)
-server -XX:+PrintGCDetails -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -Xms1600m -Xmx1600m -Xverify:none -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/log/plan01.hprof
full gc 过程: 15次=》old =>old大=》young变小=》young持续小=》young gc 频繁=>full gc
heap out of range: full gc =>old 不能变大(young 足够小)=》full gc后不能增大old的空间 容不下新来的数据。
在这里插入图片描述

  1. 使用visal vm 和mat图形化分析

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

排查出问题:DruidDataSource比例最高 在线程池的destroy线程中,排查可能是druid的数据源异常配置问题:

  1. remove-abandoned: false=>remove-abandoned: true。
    相关的其他配置 正常
    time-between-eviction-runs-millis: 60000 # 1 minute
    min-evictable-idle-time-millis: 300000 # 5 minutes
    useGlobalDataSourceStat: false
    druid配置导致堆溢出 (https://blog.csdn.net/lypeng13/article/details/121911981)
    改动后观察启动后的 E O区的占用变化和之前趋势对比情况。和FullGc在相同时间的变化趋势
    增大heap大小观察full gc

  2. 导出dump文件的方式 1. 命令 2. 工具 3. 代码

(1)docker file 文件启动文件,堆溢出自动导出
​-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/log/plan01.hprof
(2)
public class FullGCHeapDump {
private static HotSpotDiagnosticMXBean hotspotMBean;
private static long lastFullGCTime = -1; // To store the time of the last Full GC
private static final long THRESHOLD = 15000; // 2 seconds in milliseconds

// Method to trigger a heap dump
public static void dumpHeap(String filePath) {if (hotspotMBean == null) {try {hotspotMBean = ManagementFactory.newPlatformMXBeanProxy(ManagementFactory.getPlatformMBeanServer(),"com.sun.management:type=HotSpotDiagnostic",HotSpotDiagnosticMXBean.class);} catch (IOException e) {e.printStackTrace();}}try {// Dump the heap to the specified filehotspotMBean.dumpHeap(filePath, true);System.out.println("Heap dump created at: " + filePath);} catch (IOException e) {e.printStackTrace();}
}@PostConstruct
public void postConstruct(){// Keep the application running so we can monitor GC eventsSystem.out.println("Monitoring for Full GC events...");// Register GC notification listenerfor (GarbageCollectorMXBean gcBean : ManagementFactory.getGarbageCollectorMXBeans()) {NotificationEmitter emitter = (NotificationEmitter) gcBean;emitter.addNotificationListener(new NotificationListener() {@Overridepublic void handleNotification(Notification notification, Object handback) {String notificationType = notification.getType();if (notificationType.equals("com.sun.management.gc.notification")) {com.sun.management.GarbageCollectionNotificationInfo info =com.sun.management.GarbageCollectionNotificationInfo.from((javax.management.openmbean.CompositeData) notification.getUserData());// Check if the GC type is "end of major GC" or "Full GC"String gcAction = info.getGcAction();System.out.println(gcAction);if (gcAction.contains("end of major GC") || gcAction.contains("end of Full GC")) {System.out.println("Full GC detected.");long currentTime = System.currentTimeMillis();  // Get the current timeif (lastFullGCTime != -1 && (currentTime - lastFullGCTime) <= THRESHOLD) {// If two Full GCs occurred within 2 seconds, trigger the heap dumpSystem.out.println("Two Full GCs detected within 2 seconds. Triggering heap dump...");FullGCHeapDump.dumpHeap("heapdump.hprof");}// Update the time of the last Full GClastFullGCTime = currentTime;}}}}, null, null);}
}

}
5. mat实例分析查找追踪堆栈和可能得内存泄漏点

模拟堆栈溢出

@PostMapping(“post”)
public void post(){
// simulate full gc
int maxValue = Integer.MAX_VALUE;
List list = new ArrayList<>();
while (true){
for (int i = 0; i < maxValue; i++) {
list.add(new AchResult());
}
}


http://www.ppmy.cn/ops/127135.html

相关文章

Python 多线程学习与使用

Python 多线程学习与使用 目录 引言&#xff1a;为什么需要多线程&#xff1f;Python中的线程基础 2.1 什么是线程&#xff1f; 2.2 Python的threading模块 2.3 创建和启动线程线程同步与互斥 3.1 竞态条件 3.2 锁&#xff08;Lock&#xff09; 3.3 可重入锁&#xff08;RLoc…

Canmv k230 C++案例1.2——image classify项目 C++代码分析(待完成)

这部分为初学&#xff0c;所以手头最好有本工具书便于查阅 01 代码初步注释 // 这里是一些定义配置 // 时间的标准库 #include <chrono> // 写入或读取文件的标准库 #include <fstream> // 文件输入输出的标准库&#xff0c;流模型 #include <iostream> //…

在Flask中记录用户端的完整访问记录,包括请求和响应信息以及用户访问IP

在Flask中记录用户端的完整访问记录&#xff0c;包括请求和响应信息以及用户访问IP&#xff0c;可以通过自定义中间件&#xff08;或称为请求预处理和后处理函数&#xff09;来实现。Flask本身提供了装饰器和信号机制来帮助我们实现这一功能。 以下是一个基本的实现步骤&#…

搭建LeNet-5神经网络,并搭建自己的图像分类训练和测试的模板,模板通用!!!均有详细注释。

本文任务&#xff1a; 1、构建LeNet神经网络。 2、搭建图像分类训练和测试的通用模板。 3、训练出自己的模型。 4、验证模型效果。 LeNet论文地址&#xff1a;原文地址http://papers.nips.cc/paper/4824-imagenet-classification-with-deep-convolutional-neural-networks…

爬虫逆向学习(十二):一个案例入门补环境

此分享只用于学习用途&#xff0c;不作商业用途&#xff0c;若有冒犯&#xff0c;请联系处理 反爬前置信息 站点&#xff1a;aHR0cDovLzEyMC4yMTEuMTExLjIwNjo4MDkwL3hqendkdC94anp3ZHQvcGFnZXMvaW5mby9wb2xpY3k 接口&#xff1a;/xjzwdt/rest/xmzInfoDeliveryRest/getInfoDe…

git clone 鉴权失败

git clone 鉴权失败问题 1. 问题描述2. 解决方法 1. 问题描述 使用git clone自己的代码报如下错误&#xff1a; 正克隆到 xxx... Username for https://github.com: Password for https://xxxgithub.com: remote: Support for password authentication was removed on Augu…

【Flutter】页面布局:线性布局(Row 和 Column)

在 Flutter 中&#xff0c;布局&#xff08;Layout&#xff09;是应用开发的核心之一。通过布局组件&#xff0c;开发者可以定义应用中的控件如何在屏幕上排列。Row 和 Column 是 Flutter 中最常用的两种线性布局方式&#xff0c;用于水平和垂直排列子组件。在本教程中&#xf…

Unity中通过给定的顶点数组生成凸面体的方法参考

这里我们使用了Quickhull for Unity插件&#xff0c;其实就是一个ConvexHullCalculator.cs文件&#xff0c;代码如下&#xff1a; /*** Copyright 2019 Oskar Sigvardsson** Permission is hereby granted, free of charge, to any person obtaining a copy* of this software…