当前位置:网站首页>Oom happened. Do you know the reason and how to solve it?
Oom happened. Do you know the reason and how to solve it?
2022-07-06 09:33:00 【Laugh at Fengyun Road】
Catalog
- Preface
- 1、 Out of heap memory (Java heap space)
- 2、 Permanent generation space / Meta space (Permgen space/ metaspace)
- 3、GC overhead limit exceeded
- 4、 Method stack overflow (Unable to create new native thread)
- 5、swap Area overflow (Out of swap space)
- 6、 Allocate large arrays (Requested array size exceeds VM limit)
- 7、Direct buffer memory
- 8、Kill process or sacrifice child
- Conclusion
Preface
Lu java Code students , More or less, you will encounter memory overflow (OOM) Scene , But it causes OOM There is more than one reason . Let's summarize the common OOM The reasons and solutions .
1、 Out of heap memory (Java heap space)
reason :
- There may be large object assignments in the code , Usually a big tree group .
- Possible memory leak , Lead to many times GC after , Still can't find a block of memory large enough to hold the current object , Commonly used in the use of File Wait for resources not to be recycled .
- More than expected visits 、 Data volume , Usually the upstream system request traffic soars , Common in all kinds of promotions 、 Seckill activity , You can check whether there is a sharp peak in combination with business traffic indicators .
Solution :
- For most cases , Usually it's just through -Xmx Turn up the parameters JVM Heap memory is enough . If it's still not solved , You can refer to the following situations for handling .
- If it's a super object , Check its rationality , For example, whether all the results of the database are queried at one time , And there's no limit to the number of results .
- If it's peak business pressure , Consider adding machine resources , Or do current limiting and degrading operation .
- If it's a memory leak , You need to find the holding object , Modify the code design , Like closing a connection that has not been released .
2、 Permanent generation space / Meta space (Permgen space/ metaspace)
reason :
- Permanent generation is HotSot The specific implementation of virtual machine to method area , Store class information loaded by virtual machine 、 Constant pool 、 Static variables ,JIT Compiled code, etc
- Perngen Usage and load into memory class The number of / Size is positively correlated
Solution :
- Check whether the space is permanently replaced ( Launch parameters :-XX:MaxPermSize) Or meta space ( Launch parameters :-XX:MaxMetaspaceSize) Set too small .
- Check whether there are a lot of reflection operations in the code
- dump After through mat Check if there are a large number of proxy classes generated by reflection
- Application deployment times error , It is likely that the application has not been restarted , Results in multiple copies of class Information , restart JVM Can solve
3、GC overhead limit exceeded
reason :
- When java Process cost 98% Do it in the above time GC And it can't be recycled 2% This exception will be thrown in the heap memory of .
- Heap memory is too small
Solution :
- Check whether there are a lot of dead loops or code using large memory in the project , Optimize the code
- dump Memory , Check for memory leaks , without , Increase memory .
4、 Method stack overflow (Unable to create new native thread)
reason :
- The number of threads exceeds the maximum number of threads of the operating system ulimit Limit
- The number of threads exceeds kernal.pid_max
- native Out of memory
Solution :
- Upgrade configuration , Provide more memory for the machine
- Reduce Java heap space size
- Fix the thread leak problem of the application
- Limit thread pool size
- Use -Xss Parameter reduce the thread stack size
- Raise height OS The maximum number of threads in the layer : perform ulimit -a View the maximum number of threads limit , Use ulimit -u xx Adjust the maximum number of threads limit
5、swap Area overflow (Out of swap space)
This error indicates that all available virtual memory has been exhausted . Virtual memory (Virtual Memory) By physical memory (Physical) And swap space (Swap Space) Two parts . When the virtual memory requested by the runtime program overflows, it will report Out of swap space error .
reason :
- Not enough address space
- Physical memory has run out
- Local memory leak of application , For example, keep applying for local memory , Without releasing
- perform jmap -histo:live command , Enforcement Full GC; If the memory drops significantly after several executions , It is basically confirmed as Direct ByteBuffer problem
Solution :
- Upgrade the address space to 64bit
- Use Arthas Check if it is Inflater/Deflater Decompression problem , If it is , Show call end Method
- Direct ByteBuffer The problem can be solved by starting parameters –XX:MaxDirectMemorySize Lower the threshold
- enlarge swap Partition size or increase the machine memory size
- Isolated deployment , Avoid fighting
6、 Allocate large arrays (Requested array size exceeds VM limit)
reason :
This situation is generally caused by unreasonable array allocation requests , Before allocating memory for an array ,JVM An inspection will be carried out . Whether the array to be allocated can be addressed in the platform , If you can't address, you will throw this error .
Solution :
Check whether there is a place to create super large arrays in the code
7、Direct buffer memory
Java Allow applications to pass through Direct ByteBuffer Direct access to out of heap memory , Many high-performance programs pass Direct ByteBuffer Combined with memory mapping file (Memory MappedFile) High speed IO
reason :
Direct ByteBuffer The default size is 64MB, Once the use exceeds the limit , Will throw Direct buffer memory error .
Solution :
Java Only through ByteBuffer.allocateDirect Methods use DirectByteBuffer, therefore , Can pass Arthas And other online diagnostic tools intercept this method for troubleshooting .
- Check for direct or indirect use of NIO, Such as netty,jetty etc.
- Through the startup parameters -XX:MaxDirectMemorySize adjustment Direct ByteBuffer Upper limit value
- Check JVM Whether the parameter has -XX:+DisableExplicitGC Options , If there is one, remove it , Because this parameter makes System.gc() invalid
- Check the code of off heap memory , Confirm whether there is memory leak ; Or call through reflection sun.misc.Cleaner Of clean() Methods to actively release Direct ByteBuffer Memory space held .
- The memory capacity is really not enough , Upgrade configuration
8、Kill process or sacrifice child
There is a kernel job (Kernel Job) be known as Out of Memory Killer, It will be in the case of very low available memory “ Kill ”(kill) Some processes .OOM Killer All processes will be scored , Then the lower scoring process “ Kill ”, Specific scoring rules can be referred to Surviving the Linux OOM Killer.
Different from other OOM error ,Kill processorsacrifice child Mistakes are not caused by JVM Level triggered , It's triggered at the operating system level .
reason :
By default ,Linux The kernel allows processes to request more memory than the system can use , Through this kind of “ Peak shifting multiplexing ” In this way, system resources can be used more effectively .
However , This way will inevitably bring some “ Oversold ” risk . For example, some processes continue to occupy system memory , And then cause other processes to have no available memory . here , The system will automatically activate OOM Killer, Look for low scoring processes , And its “ Kill ”, Free up memory resources .
Solution :
- Upgrade server configuration / Isolated deployment , Avoid contention .
- OOM Killer tuning .
Conclusion
Okay , I'll share it with you today . If this article helps you , Welcome to thumb up & Collection & Share , This is for me to continue to share & It's very important to create quality articles . thank
-------------- end ----------------
WeChat official account : Below scan QR code
or Search for Laugh at Fengyun Road
Focus on , Get more big data dry goods !
边栏推荐
- Servlet learning diary 7 -- servlet forwarding and redirection
- 【shell脚本】——归档文件脚本
- Redis之Lua脚本
- Leetcode problem solving 2.1.1
- Intel distiller Toolkit - Quantitative implementation 2
- CSP salary calculation
- 基于B/S的影视创作论坛的设计与实现(附:源码 论文 sql文件 项目部署教程)
- Redis' performance indicators and monitoring methods
- Selenium+Pytest自动化测试框架实战(下)
- Processes of libuv
猜你喜欢
基于WEB的网上购物系统的设计与实现(附:源码 论文 sql文件)
IDS cache preheating, avalanche, penetration
Intel distiller Toolkit - Quantitative implementation 2
Full stack development of quartz distributed timed task scheduling cluster
QDialog
解决小文件处过多
Pytest parameterization some tips you don't know / pytest you don't know
Withdrawal of wechat applet (enterprise payment to change)
Master slave replication of redis
Pytest's collection use case rules and running specified use cases
随机推荐
Kratos战神微服务框架(二)
Pytest's collection use case rules and running specified use cases
Global and Chinese market of electric pruners 2022-2028: Research Report on technology, participants, trends, market size and share
Pytest parameterization some tips you don't know / pytest you don't know
基于B/S的网上零食销售系统的设计与实现(附:源码 论文 Sql文件)
QML type: locale, date
[Yu Yue education] Wuhan University of science and technology securities investment reference
Selenium+pytest automated test framework practice (Part 2)
Redis cluster
为什么要数据分层
AcWing 2456. 记事本
LeetCode41——First Missing Positive——hashing in place & swap
Global and Chinese market of capacitive displacement sensors 2022-2028: Research Report on technology, participants, trends, market size and share
Multivariate cluster analysis
Global and Chinese market for annunciator panels 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese market of bank smart cards 2022-2028: Research Report on technology, participants, trends, market size and share
Chapter 1 :Application of Artificial intelligence in Drug Design:Opportunity and Challenges
Research and implementation of hospital management inpatient system based on b/s (attached: source code paper SQL file)
Global and Chinese market of appointment reminder software 2022-2028: Research Report on technology, participants, trends, market size and share
Connexion d'initialisation pour go redis