使用Arthas对tomcat进行jvm优化

因为开发的项目太卡了,启动时间长,内存占用又高,又没有人优化,我想趁此机会优化一下,也学习学习,

这是Arthas的dashboard返回的参数

ID   NAME                          GROUP          PRIORITY  STATE    %CPU      DELTA_TIM TIME      INTERRUPT DAEMON
82   Timer-for-arthas-dashboard-97 system         5         RUNNABLE 0.31      0.015     0:0.062   false     true
2    Reference Handler             system         10        WAITING  0.0       0.000     0:0.000   false     true
3    Finalizer                     system         8         WAITING  0.0       0.000     0:0.015   false     true
4    Signal Dispatcher             system         9         RUNNABLE 0.0       0.000     0:0.000   false     true
5    Attach Listener               system         5         RUNNABLE 0.0       0.000     0:0.000   false     true
22   RMI TCP Accept-0              system         5         RUNNABLE 0.0       0.000     0:0.000   false     true
23   RMI TCP Accept-1099           system         5         RUNNABLE 0.0       0.000     0:0.000   false     true
24   RMI TCP Accept-0              system         5         RUNNABLE 0.0       0.000     0:0.000   false     true
26   RMI Scheduler(0)              system         5         TIMED_WA 0.0       0.000     0:0.000   false     true
32   GC Daemon                     system         2         TIMED_WA 0.0       0.000     0:0.000   false     true
54   arthas-timer                  system         5         WAITING  0.0       0.000     0:0.000   false     true
Memory                    used    total    max     usage    GC
heap                      1211M   1434M    3580M   33.85%   gc.ps_scavenge.count          20
ps_eden_space             924M    1019M    1046M   88.35%   gc.ps_scavenge.time(ms)       495
ps_survivor_space         134M    135M     135M    100.00%  gc.ps_marksweep.count         3
ps_old_gen                152M    279M     2685M   5.69%    gc.ps_marksweep.time(ms)      194
nonheap                   115M    118M     -1      98.05%
code_cache                31M     32M      240M    13.20%
metaspace                 75M     76M      -1      98.28%
compressed_class_space    8M      9M       1024M   0.87%
Runtime
os.name                                                     Windows 11
os.version                                                  10.0
java.version                                                1.8.0_341
java.home                                                   D:\WorkSpace\Java\jre
systemload.average                                          -1.00
processors                                                  16
timestamp/uptime                                            Tue Apr 30 09:42:33 CST 2024/1284s

说明:

ID : java级别的线程ID

NAME : 线程名

GROUP : 线程组名  

PRIORITY : 线程优先级,分为10个级别,数字越大,优先级越高

STATE : 线程的状态

CPU : 线程消耗的cpu占比,采样100ms ,将所有线程在这100ms内的使用量求和 ,再算出每个线程的cpu使用占比

TIME: 线程运行的总时间,数据格式为分 : 秒

INTERRUPIED: 线程当前的中断位状态

DAEMON :  是否是守护线程 

再往catalina.bat复制以下参数

set CATALINA_OPTS=-Xms1536m -Xmx1536m -XX:NewRatio=3 -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=256m -XX:ReservedCodeCacheSize=256m -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -XX:InitiatingHeapOccupancyPercent=35 -XX:G1HeapRegionSize=32M -XX:G1ReservePercent=20 -XX:G1HeapWastePercent=5 -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:D:/Tomcat/logs/gc.log -Djava.util.concurrent.ForkJoinPool.common.parallelism=16

放在第二行就好啦

然后保存再重新启动tomcat,此时再运行Arthas

这时参数已经改变了

ID   NAME                          GROUP          PRIORITY  STATE    %CPU      DELTA_TIM TIME      INTERRUPT DAEMON
2    Reference Handler             system         10        WAITING  0.0       0.000     0:0.000   false     true
3    Finalizer                     system         8         WAITING  0.0       0.000     0:0.015   false     true
5    Signal Dispatcher             system         9         RUNNABLE 0.0       0.000     0:0.000   false     true
6    Attach Listener               system         5         RUNNABLE 0.0       0.000     0:0.000   false     true
23   RMI TCP Accept-0              system         5         RUNNABLE 0.0       0.000     0:0.000   false     true
24   RMI TCP Accept-1099           system         5         RUNNABLE 0.0       0.000     0:0.000   false     true
25   RMI TCP Accept-0              system         5         RUNNABLE 0.0       0.000     0:0.000   false     true
27   GC Daemon                     system         2         TIMED_WA 0.0       0.000     0:0.000   false     true
29   RMI Scheduler(0)              system         5         WAITING  0.0       0.000     0:0.000   false     true
52   arthas-timer                  system         5         WAITING  0.0       0.000     0:0.000   false     true
55   arthas-NettyHttpTelnetBootstr system         5         RUNNABLE 0.0       0.000     0:0.000   false     true
Memory                    used    total    max     usage    GC
heap                      383M    1536M    1536M   24.94%   gc.g1_young_generation.count  9
g1_eden_space             256M    352M     -1      72.73%   gc.g1_young_generation.time(m 250
g1_survivor_space         64M     64M      -1      100.00%  s)
g1_old_gen                63M     1120M    1536M   4.11%    gc.g1_old_generation.count    0
nonheap                   77M     79M      760M    10.25%   gc.g1_old_generation.time(ms) 0
code_cache                22M     22M      256M    8.78%
metaspace                 49M     50M      256M    19.36%
compressed_class_space    5M      6M       248M    2.35%
Runtime
os.name                                                     Windows 11
os.version                                                  10.0
java.version                                                1.8.0_341
java.home                                                   D:\WorkSpace\Java\jre
systemload.average                                          -1.00
processors                                                  16
timestamp/uptime                                            Tue Apr 30 10:27:38 CST 2024/1033s

然后之前的内存有时候飙高的问题得到了缓解,从之前的1G-3.5G,变成了500M-1.3G,内存占用变少,性能也得到了优化

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值