JVM 参数设置
参考文献:http://www.oracle.com/technetwork/java/gc-tuning-5-138395.html
某个大流量网站中JVM参数设置如下:
-Xms10000M -Xmx10000M -Xmn5000M
-Xss128k
-XX:PermSize=256m
-XX:MaxPermSize=512m
-XX:+UseParNewGC
-XX:ParallelGCThreads=8 默认开启回收线程数(并行GC线程数+3)/4
-XX:SurvivorRatio=6
-XX:TargetSurvivorRatio=90
-XX:MaxTenuringThreshold=30 控制对象在新生代存活的最大次数
-XX:+UseConcMarkSweepGC
-XX:+UseCMSCompactAtFullCollection 下面两个参数,由于CMS会产生垃圾浮点,所以每执行5次full GC
-XX:CMSFullGCsBeforeCompaction=5 内存就进行整理
-XX:CMSInitiatingOccupancyFraction=55 旧生代使用55%的比例触发full GC
-XX:SoftRefLRUPolicyMSPerMB=0
-XX:CMSIncrementalSafetyFactor=20 ??????????????
-XX:+CMSIncrementalMode ?????????????
-XX:+UseCMSInitiatingOccupancyOnly 禁止hotspot自行触发CMS GC
-XX:+PrintGCDetails -XX:+PrintGCTimeStamp
考虑的是持久代的GC也可以设置:-XX:+CMSPermGenSweepingEnabled,-XX:+CMSClassUnloadingEnabled
额外参数需要考虑的:
-XX:+DisableExplicitGC禁止System.gc()
-XX:SoftRefLRUPolicyMSPerMB
softly reachable objects will remain alive for some amount of time after
the last time they were referenced. The default value is one second of
lifetime per free megabyte in the heap,我觉得没必要等1秒;
如果在CMS算法中配置了: -XX:+UseAdaptiveSizePolicy 表示堆中各个区的比例由JVM自己分配即动态变化
-XX:+DisableExplicitGC禁止System.gc()
CMS算法
优点:
- 在Old进行回收时,对应用的暂停时间非常短,适合对latency要求高的应用
缺点:
- 内存碎片和浮动垃圾
- Old区内存分配效率低
- 回收的整个耗时比较长
- 和应用争取CPU
二、内存回收触发机制
1、YGC eden空间不足
2、CMS GC
- Old区域使用达到一定的比例,默认是92%
- 配置了CMSClassunloadingEnabled,且Perm 区域使用达到一定比例,默认92%
- hotspot自己根据估计决定是否要触发
- 在配置ExplicitGCInvokesConcurrent的情况下调用了System.gc
Full GC如果出现了Promotion failed 或Concurrent Mode Failure 时,GC采用 serial MSC
promotion failed,(Xmx-Xmn)*(100-CMSInitiatingOccupancyFraction)/100>=Xmn
三、对于CMS算法中增量模式的解释
-XX:+CMSIncrementalMode
请看原文的意思:
The concurrent collector can be used in a mode in which the concurrent phases are done
incrementally. Recall that during a concurrent phase the garbage collector thread is using a processor.
The incremental mode is meant to lessen the impact of long concurrent phases by periodically stopping
the concurrent phase to yield back the processor to the application. This mode
(referred to here as “i-cms”) divides the work done by concurrently by the collector into small chunks
of time which are scheduled between young generation collections. This feature is useful when
applications that need the low pause times provided by the concurrent collector are run on machines
with small numbers of processors (e.g., 1 or 2).
The concurrent collection cycle typically includes the following steps:
stop all application threads; do the initial mark; resume all application threads
do the concurrent mark (uses one procesor for the concurrent work)
do the concurrent pre-clean (uses one processor for the concurrent work)
stop all application threads; do the remark; resume all application threads
do the concurrent sweep (uses one processor for the concurrent work)
do the concurrent reset (uses one processor for the concurrent work)
Normally, the concurrent collector uses one processor for the concurrent work for the entire
concurrent mark phase, without (voluntarily) relinquishing it. Similarly, one processor is used for the
entire concurrent sweep phase, again without relinquishing it. This processor utilization can be too
much of a disruption for applications with pause time constraints, particularly when run on systems
with just one or two processors. i-cms solves this problem by breaking up the concurrent phases into
short bursts of activity, which are scheduled to occur mid-way between minor pauses.
I-cms uses a "duty cycle" to control the amount of work the concurrent collector is allowed to do
before voluntarily giving up the processor. The duty cycle is the percentage of time between young
generation collections that the concurrent collector is allowed to run. I-cms can automatically compute
the duty cycle based on the behavior of the application (the recommended method), or the duty cycle
can be set to a fixed value on the command line.
The following command-line options control i-cms (see below for recommendations for an initial set of
options):
-XX:+CMSIncrementalMode default: disabled
This flag enables the incremental mode. Note that the concurrent collector must be enabled (with
-XX:+UseConcMarkSweepGC) for this option to work.
-XX:+CMSIncrementalPacing default: disabled
This flag enables automatic adjustment of the incremental mode duty cycle based on statistics
collected while the JVM is running.
-XX:CMSIncrementalDutyCycle=<N> default: 50
This is the percentage (0-100) of time between minor collections that the concurrent collector is
allowed to run. If CMSIncrementalPacing is enabled, then this is just the initial value.
-XX:CMSIncrementalDutyCycleMin=<N> default: 10
This is the percentage (0-100) which is the lower bound on the duty cycle when CMSIncrementalPacing
is enabled.
-XX:CMSIncrementalSafetyFactor=<N> default: 10
This is the percentage (0-100) used to add conservatism when computing the duty cycle.
-XX:CMSIncrementalOffset=<N> default: 0
This is the percentage (0-100) by which the incremental mode duty cycle is shifted to the right within
the period between minor collections.
-XX:CMSExpAvgFactor=<N> default: 25
This is the percentage (0-100) used to weight the current sample when computing exponential
averages for the concurrent collection statistics.
5.4.9.2 Recommended Options for i-cms
When trying i-cms, we recommend the following as an initial set of command line options:
-XX:+UseConcMarkSweepGC \
-XX:+CMSIncrementalMode \
-XX:+CMSIncrementalPacing \
-XX:CMSIncrementalDutyCycleMin=0 \
-XX:+CMSIncrementalDutyCycle=10 \
-XX:+PrintGCDetails \
-XX:+PrintGCTimeStamps \
-XX:-TraceClassUnloading
所以要慎重的使用该参数,不要使用JVM自己收集JVM信息去触发GC,自己使用过该参数,深有体会,full gc不可控。
分享到:
相关推荐
JVM参数设置是优化Java应用性能的关键环节,它可以帮助我们控制JVM的行为,如内存分配、垃圾回收策略、线程调度等。下面将详细介绍一些重要的JVM参数及其作用。 1. 内存设置: - `-Xms` 和 `-Xmx`:这两个参数用于...
### JVM参数设置详解 在Java应用开发与维护过程中,JVM(Java虚拟机)的配置至关重要,它直接影响到应用程序的性能表现与稳定性。本文将基于提供的文件内容,深入解析Linux环境下JVM的基本参数设置方法及原理。 ##...
JVM参数设置对于调整应用程序的性能、优化资源利用和确保系统稳定性至关重要。本篇文章将深入探讨JVM参数设置的各个方面。 首先,JVM参数主要分为两大类:标准参数和非标准参数。标准参数以“-X”或“-XX:”开头,...
JVM参数设置是Java应用程序优化的关键环节,直接影响到程序的性能和稳定性。下面将详细解释提供的JVM参数及其对性能的影响。 1. **堆大小设置**: - `-Xmx` 和 `-Xms` 用于设定JVM的最大堆(`Max Heap Size`)和最小...
was使用及参数设置 was使用及参数设置 was使用及参数设置
非堆内存的初始大小和最大大小可以通过`-XX:PermSize`和`-XX:MaxPermSize`来设置,但需要注意,这些参数在Java 8之后已不再适用,因为永久代已被元空间取代。对于元空间,JVM会根据需要自动调整大小,但可以使用`-XX...
This document is a compilation of all the JVM options for various versions of the JVM on primarily SPARC/Solaris Platform. The descriptions for each option are taken mostly verbatim from the reference...
- 参数设置错误,例如`-Xms`大于`-Xmx`,或者`-XX:PermSize`大于`-XX:MaxPermSize`。 - 总内存需求超过了JVM内存的最大限制,这可能受到操作系统或物理内存的约束。 3. **eclipse.ini配置**: 在eclipse.ini文件...
本文将详细介绍一些常用的JVM参数设置,这些参数适用于线上关键业务系统,并且具有较高的通用性。 #### 二、学习资源推荐 1. **开源项目启动脚本**:参考成熟的开源项目如ElasticSearch和Cassandra的启动脚本可以...
1. JVM 参数设置 JVM 参数的设置是指对 JVM 应用程序的配置,以提高应用程序的运行效率。例如,我们可以将 -Xmx 设置为 12g,以提高 JVM 的堆大小。又如,我们可以将 -XX:LargePageSizeInBytes 设置为 128m,以提高...
### Tomcat 6.0 修改启动内存设置及 Java JVM 参数配置详解 #### 一、背景与目的 在部署和运行 Java Web 应用时,合理地配置应用服务器(如 Apache Tomcat)的内存是非常重要的。这不仅可以提升应用程序的性能,还...
1. **查看当前配置**:首先查看当前JVM参数设置是否合理。 2. **调整JVM参数**:根据应用程序的实际需求调整JVM参数。 - 例如:可以将初始堆内存大小设为256MB,最大堆内存大小设为512MB。 - 将永久代的初始大小设...
在"jvmSample-master"项目中,我们可以通过模拟不同的负载情况来测试不同JVM参数设置下的性能表现。例如,调整-Xms和-Xmx参数,观察程序启动速度和运行稳定性;使用-XX:NewRatio和-XX:SurvivorRatio调整年轻代和老年...
本系列课程从JVM基础到高级实战,老师手把手教你如何进行JVM...1.3JVM参数设置思路1.4JVM调优常用指令说明 第七节:JVM项目实战 1.1案例背景 1.2排查步骤 1.3.arthas 1.3.1.arthas简介 1.3.2.arthas实战 1.3总结
本文将深入探讨JVM的常用参数设置,以及它们如何影响Java应用程序的运行。 一、JVM内存设置 1. **堆内存**: - `-Xms`:初始堆大小,例如`-Xms256m`表示初始分配256MB内存。 - `-Xmx`:最大堆大小,例如`-Xmx...
### 设置Eclipse的JVM参数 #### 一、引言 在进行Java开发时,Eclipse作为一款广泛使用的集成开发环境(IDE),其性能优化对于提高开发效率和应用稳定性至关重要。其中,设置合适的JVM(Java虚拟机)参数是优化...
理解JVM参数设置,可以帮助开发者在面临性能瓶颈时做出明智决策,优化应用程序的内存使用,预防和处理内存溢出问题。同时,这也是面试中常见的话题,掌握这部分知识将大大提高你的专业素养。 总的来说,“蚂蚁课堂-...
将机器的JVM参数设置到最优 一般的Java都不需要进行JVM优化 减少代码层面造成的GC问题(STW) 减少使用全局变量、大对象以及减少创建对象的数量 通过代码解决GC情况比优化JVM参数更好 架构和代码调优等级优先于JVM...
### JVM 6 详细参数分析 #### 概述 本文档深入探讨了Java 6 (JDK 6) 的JVM参数配置,旨在为开发者提供一份详尽的指南,帮助理解并合理设置JVM参数...希望本文档能够成为您探索JVM参数设置道路上的一份宝贵参考资料。