当前位置:网站首页>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 !
边栏推荐
- 【图的三大存储方式】只会用邻接矩阵就out了
- What is MySQL? What is the learning path of MySQL
- Different data-driven code executes the same test scenario
- Redis之Geospatial
- Heap (priority queue) topic
- Global and Chinese market for annunciator panels 2022-2028: Research Report on technology, participants, trends, market size and share
- Advanced Computer Network Review(4)——Congestion Control of MPTCP
- Compilation of libwebsocket
- Design and implementation of online shopping system based on Web (attached: source code paper SQL file)
- [daily question] Porter (DFS / DP)
猜你喜欢
What is MySQL? What is the learning path of MySQL
Research and implementation of hospital management inpatient system based on b/s (attached: source code paper SQL file)
Redis cluster
[OC foundation framework] - string and date and time >
Redis之五大基础数据结构深入、应用场景
基于B/S的网上零食销售系统的设计与实现(附:源码 论文 Sql文件)
Mapreduce实例(十):ChainMapReduce
小白带你重游Spark生态圈!
Redis connection redis service command
Reids之删除策略
随机推荐
五层网络体系结构
The five basic data structures of redis are in-depth and application scenarios
Selenium+pytest automated test framework practice
英雄联盟轮播图自动轮播
【shell脚本】——归档文件脚本
Global and Chinese market of metallized flexible packaging 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese markets of SERS substrates 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese market of cup masks 2022-2028: Research Report on technology, participants, trends, market size and share
为拿 Offer,“闭关修炼,相信努力必成大器
基于B/S的影视创作论坛的设计与实现(附:源码 论文 sql文件 项目部署教程)
Selenium+pytest automated test framework practice (Part 2)
Advance Computer Network Review(1)——FatTree
Redis之持久化实操(Linux版)
An article takes you to understand the working principle of selenium in detail
Mapreduce实例(七):单表join
Redis' bitmap
CAP理论
【深度学习】语义分割-源代码汇总
Mapreduce实例(四):自然排序
CSP student queue