当前位置:网站首页>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 !
边栏推荐
- go-redis之初始化連接
- Global and Chinese markets of SERS substrates 2022-2028: Research Report on technology, participants, trends, market size and share
- Selenium+Pytest自动化测试框架实战(下)
- Redis之性能指标、监控方式
- Redis之cluster集群
- What is an R-value reference and what is the difference between it and an l-value?
- 【深度学习】语义分割:论文阅读:(2021-12)Mask2Former
- Sqlmap installation tutorial and problem explanation under Windows Environment -- "sqlmap installation | CSDN creation punch in"
- 解决小文件处过多
- MapReduce工作机制
猜你喜欢

QML type: locale, date

Mapreduce实例(四):自然排序

IDS' deletion policy

Lua script of redis

Multivariate cluster analysis

Mapreduce实例(八):Map端join
![[oc]- < getting started with UI> -- common controls - prompt dialog box and wait for the prompt (circle)](/img/af/a44c2845c254e4f48abde013344c2b.png)
[oc]- < getting started with UI> -- common controls - prompt dialog box and wait for the prompt (circle)

Nacos installation and service registration

Intel distiller Toolkit - Quantitative implementation 2

Detailed explanation of cookies and sessions
随机推荐
Different data-driven code executes the same test scenario
Reids之缓存预热、雪崩、穿透
Minio distributed file storage cluster for full stack development
In depth analysis and encapsulation call of requests
leetcode-14. Longest common prefix JS longitudinal scanning method
Full stack development of quartz distributed timed task scheduling cluster
Redis connection redis service command
Intel distiller Toolkit - Quantitative implementation 2
Redis之连接redis服务命令
Opencv+dlib realizes "matching" glasses for Mona Lisa
Meituan Er Mian: why does redis have sentinels?
Reids之删除策略
运维,放过监控-也放过自己吧
Selenium+pytest automated test framework practice (Part 2)
Sqlmap installation tutorial and problem explanation under Windows Environment -- "sqlmap installation | CSDN creation punch in"
Redis之Geospatial
Use of activiti7 workflow
Mapreduce实例(六):倒排索引
go-redis之初始化連接
Sentinel mode of redis