jvm 参数调优(堆 + 垃圾回收) 默认参数

本文通过具体案例介绍了Java应用程序中不同类型的垃圾回收(GC)过程及其日志解析方法。深入探讨了CMS收集器的工作原理,并提供了详细的JVM参数设置建议,帮助读者理解和优化Java应用的内存管理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

父文章 :java 定位实战

父文章 java 垃圾回收总结和面试和应用_个人渣记录仅为自己搜索用的博客-优快云博客

相关文章 

jvm调优案例 寒泉Hq的博客-优快云博客_g1 stw

JVM 调优实战--什么是调优及如何调优的思路_学亮编程手记的博客-优快云博客_调优什么意思

java 8堆理解
几种完全不同的 gc 日志,:

-- GC (CMS Initial Mark)
1. 2018-03-07T13:13:37.706-0800: 0.415: [GC (CMS Initial Mark) [1 CMS-initial-mark: 15775K(19456K)] 15893K(20416K), 0.0001372 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]

2. 2018-03-07T13:13:37.706-0800: 0.415: [CMS-concurrent-mark-start]

--  [GC (Allocation Failure) ParNew
3.2018-03-07T13:13:37.737-0800: 0.446: [GC (Allocation Failure) 2018-03-07T13:13:37.737-0800: 0.446: [ParNew: 960K->64K(960K), 0.0007581 secs] 19872K->19129K(20416K), 0.0007846 secs] [Times: user=0.01 sys=0.00, real=0.00 secs]


-- GC (Allocation Failure) ParNew (promotion failed) (concurrent mode failure)
4. 2018-03-07T13:13:37.738-0800: 0.447: [GC (Allocation Failure) 2018-03-07T13:13:37.738-0800: 0.447: [ParNew (promotion failed): 960K->960K(960K), 0.0009510 secs]2018-03-07T13:13:37.739-0800: 0.448:
 [CMS2018-03-07T13:13:37.745-0800: 0.453: [CMS-concurrent-mark: 0.013/0.038 secs] [Times: user=0.12 sys=0.01, real=0.04 secs]
 (concurrent mode failure): 19132K->19257K(19456K), 0.0490845 secs] 20025K->19257K(20416K), [Metaspace: 3395K->3395K(1056768K)], 0.0500762 secs] [Times: user=0.05 sys=0.00, real=0.05 secs]

-- GC (Allocation Failure) ParNew (promotion failed) CMS
5. 2018-03-07T13:13:37.789-0800: 0.497: [GC (Allocation Failure) 2018-03-07T13:13:37.789-0800: 0.497: [ParNew (promotion failed): 896K->959K(960K), 0.0008608 secs] 2018-03-07T13:13:37.790-0800: 0.498: 
[CMS: 19317K->19404K(19456K), 0.0451367 secs] 20153K->19404K(20416K), [Metaspace: 3395K->3395K(1056768K)], 0.0460436 secs] [Times: user=0.04 sys=0.01, real=0.05 secs]

-- Full GC 
6. 2018-03-07T13:13:37.883-0800: 0.592: [Full GC (Allocation Failure) 2018-03-07T13:13:37.884-0800: 0.592: [CMS: 19455K->19455K(19456K), 0.0410427 secs] 20415K->19626K(20416K), [Metaspace: 3395K->3395K(1056768K)], 0.0410821 secs] [Times: user=0.04 sys=0.00, real=0.04 secs]

Heap
 par new generation   total 960K, used 32K [0x00000007bec00000, 0x00000007bed00000, 0x00000007bed00000)
  eden space 896K,   3% used [0x00000007bec00000, 0x00000007bec08258, 0x00000007bece0000)
  from space 64K,   0% used [0x00000007bece0000, 0x00000007bece0000, 0x00000007becf0000)
  to   space 64K,   0% used [0x00000007becf0000, 0x00000007becf0000, 0x00000007bed00000)
 concurrent mark-sweep generation total 19456K, used 679K [0x00000007bed00000, 0x00000007c0000000, 0x00000007c0000000)
 Metaspace       used 3426K, capacity 4600K, committed 4864K, reserved 1056768K
  class space    used 369K, capacity 424K, committed 512K, reserved 1048576K

If survivor spaces are too small, copying collection overflows directly into the tenured generation. If survivor spaces are too large, they will be uselessly empty. At each garbage collection, the virtual machine chooses a threshold number, which is the number times an object can be copied before it is tenured. This threshold is chosen to keep the survivors half full. The command line option -XX:+PrintTenuringDistribution (not available on all garbage collectors) can be used to show this threshold and the ages of objects in the new generation. It is also useful for observing the lifetime distribution of an application.

 实验参数:         -Xmx2m -Xms2m  -Xmn2g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=70 -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:/Users/loufei/intellijProject/log/gc.log 默认参数查看: jinfo         实验代码:

 
 public static void main(String[] args) throws InterruptedException, IOException {

        List<String> lists = Lists.newLinkedList();
        int i = 0;
        while (true) {
            String e = i + "中共扥撒扥撒扥死扥撒等扔撒网";
            i++;
            if (i % 7 == 0) {
                lists.add(e);
            }
//
//            if (lists.size()>100){
//                for (int j = 0; j < lists.size()/10; j++) {
//                    lists.remove(j);
//                }
//            }

        }
    }

这个控制更精细
public class HeapTest {
    private static final int _1M = 1024 * 1024;

    public static void main(String[] args) throws InterruptedException {
        byte[] byte1 = new byte[2 * _1M];
        byte[] byte2 = new byte[2 * _1M];
        byte[] byte3 = new byte[2 * _1M];
        byte[] byte4 = new byte[2 * _1M];
        byte[] byte5 = new byte[2 * _1M];

        byte[] byte6 = new byte[5 * _1M];

        byte[] byte7 = new byte[2 * _1M];


    }
}


 先看 dubbo 启动参数官方配置信息地址:
https://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html#BABFAFAE
 (或者搜索Advanced Garbage Collection Options)

-xss10m = -XX:ThreadStackSize=10m
-Xmn2g = -XX:NewSize=2g

GCLOGFILE=/app/logs/trade/gc.log.`date +"%F"` (shell 脚本.)

JAVA_MEM_OPTS=" -server -Xmx4g -Xms4g -Xmn2g -XX:PermSize=128m -Xss256k  -XX:SurvivorRatio=8-XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:LargePageSizeInBytes=128m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:$GCLOGFILE"

 好文章 blog.youkuaiyun.com/fei33423/article/details/70942385

 java默认参数 : 

    java -XX:+PrintFlagsInitial  >>1.txt

JVM系列三:JVM参数设置、分析

DisableExplicitGC和Direct ByteBuffer 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值