机器概况
服务器centos8, 8g内存, 运行着4个java服务(不算zk),zookeeper,2个node服务
其中,2个java服务是主要服务,运行着网站基本数据交互和搜索接口.
效果
image.png标记出来的4个点依次是:
配置优化前的峰值
配置优化当时
配置优化后的峰值
配置优化后的谷值(大致对应最大应用jvm内存回收后)
步骤
-
sudo jps 查看对应应用的pid
-
sudo jmap -heap <pid> 查看对应进程的堆内存使用情况
[www@prod:~]$ sudo jmap -heap 589
Attaching to process ID 589, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.172-b11
using thread-local object allocation.
Parallel GC with 2 thread(s)
Heap Configuration:
MinHeapFreeRatio = 0
MaxHeapFreeRatio = 100
MaxHeapSize = 2011168768 (1918.0MB)
NewSize = 41943040 (40.0MB)
MaxNewSize = 670040064 (639.0MB)
OldSize = 83886080 (80.0MB)
NewRatio = 2
SurvivorRatio = 8
MetaspaceSize = 21807104 (20.796875MB)
CompressedClassSpaceSize = 1073741824 (1024.0MB)
MaxMetaspaceSize = 17592186044415 MB
G1HeapRegionSize = 0 (0.0MB)
Heap Usage:
PS Young Generation
Eden Space:
capacity = 445120512 (424.5MB)
used = 220195560 (209.9948501586914MB)
free = 224924952 (214.5051498413086MB)
49.46875150970351% used
From Space:
capacity = 11010048 (10.5MB)
used = 10060200 (9.594154357910156MB)
free = 949848 (0.9058456420898438MB)
91.37289864676339% used
To Space:
capacity = 12058624 (11.5MB)
used = 0 (0.0MB)
free = 12058624 (11.5MB)
0.0% used
PS Old Generation
capacity = 93847552 (89.5MB)
used = 22882704 (21.822647094726562MB)
free = 70964848 (67.67735290527344MB)
24.3828459158956% used
20553 interned Strings occupying 2519416 bytes.
上面的java进程里, 配置的最大堆内存为 1918.0MB, 而实际运行中, 新生代和老年代加起来不过514M(424.5+89.5),其中老年代不过使用了 24%. 所以最大 512M的堆内存就足够了.
- 服务启动命令添加 Xms Xmx 参数
nohup java -Xms512m -Xmx512m -jar xxx.jar 其他参数 >logs/run.log 2>&1 &
网友评论