我们作为普通的开发人员很少能够接触到JVM调优,但是现在基本上所有的职位要求都会加上有JVM调优经验优先,虽然我们没用过但是我们还是应该了解知道的,下面就是JVM调优的一点知识点。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/20995.html
文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/20995.html
调优时机文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/20995.html
a. heap 内存(老年代)持续上涨达到设置的最大内存值;文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/20995.html
b. Full GC 次数频繁;文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/20995.html
c. GC 停顿时间过长(超过1秒);文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/20995.html
d. 应用出现OutOfMemory 等内存异常;文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/20995.html
e. 应用中有使用本地缓存且占用大量内存空间;文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/20995.html
f. 系统吞吐量与响应性能不高或下降。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/20995.html
文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/20995.html
调优原则文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/20995.html
a. 多数的Java应用不需要在服务器上进行JVM优化;文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/20995.html
b. 多数导致GC问题的Java应用,都不是因为我们参数设置错误,而是代码问题;文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/20995.html
c. 在应用上线之前,先考虑将机器的JVM参数设置到最优(最适合);文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/20995.html
d. 减少创建对象的数量;文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/20995.html
e. 减少使用全局变量和大对象;文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/20995.html
f. JVM优化是到最后不得已才采用的手段;文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/20995.html
g. 在实际使用中,分析GC情况优化代码比优化JVM参数更好;文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/20995.html
文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/20995.html
调优目标文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/20995.html
a. GC低停顿;文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/20995.html
b. GC低频率;文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/20995.html
c. 低内存占用;文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/20995.html
d. 高吞吐量;文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/20995.html
文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/20995.html
调优步骤文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/20995.html
a. 分析GC日志及dump文件,判断是否需要优化,确定瓶颈问题点;文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/20995.html
b. 确定jvm调优量化目标;文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/20995.html
c. 确定jvm调优参数(根据历史jvm参数来调整);文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/20995.html
d. 调优一台服务器,对比观察调优前后的差异;文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/20995.html
e. 不断的分析和调整,知道找到合适的jvm参数配置;文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/20995.html
f. 找到最合适的参数,将这些参数应用到所有服务器,并进行后续跟踪。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/20995.html