当前位置:网站首页>JVM memory tuning method
JVM memory tuning method
2022-06-29 04:27:00 【xmh-sxh-1314】
Yes JVM The main purpose of memory system level tuning is to reduce GC The frequency and Full GC The number of times .
1.Full GC
The whole pile will be sorted out , Include Young、Tenured and Perm.Full GC Because you need to recycle the entire heap , So it's slower , So it should be reduced as much as possible Full GC The number of times .
2. Lead to Full GC Why
1) The old generation (Tenured) Be full of
When tuning, try to keep objects in the new generation GC It's recycled 、 Keep objects alive for a long time in the new generation and avoid creating too large objects and arrays directly in the old generation .
2) Lasting generation Pemanet Generation The space is insufficient
increase Perm Gen Space , Avoid too many static objects , Control the proportion of new generation and old generation
3)System.gc() Called by display
Do not manually trigger garbage collection , Try to rely on JVM Its own mechanism
In the face of JVM In the process of tuning , A big part of the work is about FullGC The adjustment of , The following details the corresponding JVM Tuning methods and steps .
JVM Performance tuning methods and steps
1. monitor GC The state of
Using a variety of JVM Tools , View the current log , Analyze the present JVM Parameter setting , And analyze the current heap memory snapshot and gc journal , According to the actual area memory partition and GC execution time , Think whether to optimize .
For example : Some phenomena before system crash :
Every time garbage collection time is longer and longer , By the previous 10ms Extend to 50ms about ,FullGC There's also time before 0.5s Extend to 4、5s
FullGC More and more times , The most frequent time is less than 1 Every minute FullGC
Older generations have more and more memory and every time FullGC In the following years, no memory will be released
After that, the system will not be able to respond to new requests , Arrive gradually OutOfMemoryError The critical value of , This is the time to analyze JVM memory dump dump.
2. Make a heap of dump file
adopt JMX Of MBean Generate the current Heap Information , The size is one 3G( The size of the whole pile ) Of hprof file , If not started JMX Can pass Java Of jmap Command to generate the file .
3. analysis dump file
Open this. 3G The heap information file , Obviously, it's just Window The system doesn't have that much memory , High configuration Linux, Several tools open the file :
Visual VM
IBM HeapAnalyzer
JDK Self contained Hprof Tools
Mat(Eclipse Special static memory analysis tool ) Recommended
remarks : The file is too large , It is recommended to use Eclipse Special static memory analysis tool Mat Open analysis .
4. The results of the analysis , Decide if you need to optimize
If the parameters are set reasonably , There is no timeout log in the system ,GC The frequency is not high ,GC Time consuming is not high , Then there's no need for GC Optimize , If GC For more than 1-3 second , Or frequently GC, You have to optimize .
notes : If the following indicators are met , In general, there is no need for GC:
Minor GC Execution time is less than 50ms;
Minor GC Infrequent execution , about 10 Seconds at a time ;
Full GC Execution time is less than 1s;
Full GC Execution frequency is not frequent , No less than 10 minute 1 Time ;
5. adjustment GC Type and memory allocation
If the memory allocation is too large or too small , Or use GC The collector is slow , We should adjust these parameters first , And look for 1 One or more machines beta, Then compare the performance of the optimized machine with that of the non optimized machine , And targeted to make the final choice .
6. Constant analysis and adjustment
Through constant trial and error , Analyze and find the most suitable parameters , If the most appropriate parameter is found , Then apply these parameters to all servers .
cms Parameter optimization process
Let me continue to introduce JVM Key parameter configuration of ( For reference only ).
JVM Tuning parameters reference
1. in the light of JVM Heap settings , In general, you can go through -Xms -Xmx Limit it to a minimum 、 Maximum , In order to prevent the garbage collector at the minimum 、 The maximum amount of time required to shrink the pile , Usually put the biggest 、 The minimum setting is the same ;
2. The younger generation and the older generation will be based on the default ratio (1:2) Allocate heap memory , You can adjust the ratio between them NewRadio To adjust the size between the two , It can also be used for recycling .
For example, the younger generation , adopt -XX:newSize -XX:MaxNewSize To set its absolute size . Again , To prevent the young generation from shrinking , We usually put -XX:newSize -XX:MaxNewSize Set to the same size .
3. It's reasonable to set up the young generation and the old generation
1) The younger generation will inevitably lead to the younger generation , The big young generation will extend the average GC The cycle of , But it will increase every time GC Time for ; Small old people lead to more frequent Full GC
2) The younger generation inevitably leads to the older generation , Small young generation will lead to ordinary GC Very frequent , But every time GC Time will be shorter ; There will be fewer older generations Full GC The frequency of
How to choose the distribution that should depend on the life cycle of the application object : If the application has a large number of temporary objects , We should choose a younger generation ; If there are relatively more persistent objects , Old age should be increased properly . But many applications don't have such obvious features .
When making a choice, we should take root in According to the following two points :
(1) In line with Full GC The principle of minimizing , Let older generation cache common objects as much as possible ,JVM The default scale for 1:2 The same thing .
(2) By observing the application for a period of time , Let's see how much memory the older generation will take up at the peak , It doesn't affect Full GC Under the premise of , According to the actual situation, we should increase the number of young people and replace them with younger ones , For example, we can control the proportion to 1:1. But we should reserve at least 1/3 The growth space of .
4. On better equipped machines ( For example, multicore. 、 Large memory ), You can choose a parallel collection algorithm for the elderly : -XX:+UseParallelOldGC .
5. Thread stack settings : Each thread will be turned on by default 1M The stack , Used to store stack frames 、 Call parameters 、 Local variables, etc , This default is too much for most applications , commonly 256K Just enough .
Theoretically , With constant memory , Reduce the stack per thread , More threads can be generated , But it's actually limited to the operating system .
边栏推荐
- ROS TF coordinate transformation Library & rewrite to create high frequency coordinate transformation broadcaster
- IDEA修改jvm内存
- 【新功能】Ambire 钱包集成了 Metis 网络
- What are the basic usage methods of MySQL
- Nuxt - set SEO related tags, page titles, icons, etc. separately for each page (page configuration head)
- Gocd is good, but talk about Jenkins
- JSX的基本使用
- 热更新流程
- Runtimeerror in yolox: dataloader worker (PID (s) 17724, 1364, 18928) exited unexpectedly
- 剑指 Offer II 040. 矩阵中最大的矩形
猜你喜欢

Five thousand years of China

yolox出现 RuntimeError: DataLoader worker (pid(s) 17724, 1364, 18928) exited unexpectedly

仿真與燒錄程序有哪幾種方式?(包含常用工具與使用方式)

JDBC learning

Multi machine LAN office artifact rustdesk use push!!!

EEG signal processing - wavelet transform series

Iterator pattern

Memo pattern
![[C language] explain the thread exit function pthread_ exit](/img/fb/96db1c712370dbb216a06440ecdc5e.png)
[C language] explain the thread exit function pthread_ exit

Blue Bridge Cup ruler method
随机推荐
Implementation of thread pool based on variable parameter template
lua-protobuff emmy-lua 轮子
Hcie security day41: theoretical learning: information collection and network detection
LabVIEW displays Unicode characters
1017 A除以B分
Idea modifying JVM memory
云主机mysql在本地电脑连接不上
使用AssetStudio/UnityStudio UABE等
Libuv library overview and comparison of libevent, libev and libuv (Reprint)
Quelles sont les méthodes de simulation et de gravure des programmes? (comprend les outils communs et la façon dont ils sont utilisés)
Live broadcast appointment AWS data everywhere series activities
How to display all MySQL databases
1015 theory of virtue and talent
[C language] address of stack memory associated with local variable 'num' returned
CTO and programmer were both sentenced because the crawler was out of control!
Nuxt - 每个页面单独设置 SEO 相关标签及网页标题、图标等(页面配置 head)
IDEA修改jvm内存
我的创作纪念日
JVM_ 16_ Garbage collector
Mécanisme d'attention du canal de fixation