Locating Out of Memory Problems Using Profiler
Background
The container where a service is located restarts frequently. Based on self-monitoring, full GC occurs frequently (about 20 times per minute) before each restart.
Procedure
- Log in to the management console.
- Click
on the left and choose Management & Governance > Application Performance Management.
- In the navigation pane, choose Application Monitoring > Metrics.
- In the tree on the left, click
next to the target environment.
- Click the Profiler Performance Analysis tab.
- Click Performance Analysis.
- Set Type to Memory, Code to All Code, and Group by to Method. It is found that two methods occupy a large amount of memory.
- In the Method Path column, find the call stack of the method based on the method name, and find the service code that calls the method.
- Locate the target service code block. A cache is used to store information about each instance. Check the calling of the SQL statement through self-monitoring. It is called 100,000 times per minute, which further proves that the cache is ineffective.
During instance information querying, the system first queries the cache. If the information cannot be found in the cache, the system queries the MySQL database. After the instance information is queried, it is stored in the cache to prevent frequent access to the database.
- Check the code. The cached key is a class that does not override the equals and hashCode methods. Therefore, when the cache obtains the value based on the key, whether the key exists in the cache is determined based on the key address. The key address transferred each time is different. Therefore, the system cannot find related information in the cache and needs to query the MySQL database. It frequently stores the queried information to the cache, causing out of memory.
Solution
Override the equals and hashCode methods for the class that is used as the key. This class has the UUID attribute. Different instances have different UUIDs. Therefore, whether two instances are the same can be determined based on UUID.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot