Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of Server memory leak

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail the example analysis of server memory leaks for you. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

Foreword: due to the previous game server, maintenance is more frequent, about once a week, and the player derivative is general, resulting in memory problems have not been obvious, did not attract enough attention. Until some time ago, the derivative was relatively sufficient, and there was no timely opening of new clothes, resulting in one of the clothes, about 5K per day. In addition, the platform is more concerned about the cost of the server, so it has to work overtime to recheck the memory leak.

Ptmalloc,jemalloc and tcmalloc are commonly used in memory management tools.

Our server uses jemalloc, so we use the matching jeprof for leak checking. I use the timing dump memory, and then through the analysis and comparison of heap files for troubleshooting.

1. Code timer adds dump code

Mallctl ("prof.dump", NULL, 0)

two。 Before startup

Export MALLOC_CONF= "background_thread:true,prof:true,prof_prefix:jeprof.out"

Export LD_PRELOAD=$real_path/program/lib/libjemalloc.so

3. Analyze heap files

Export pdf file jeprof-- show_bytes-- pdf. / yourprogram jeprof.out.xxx.xx.mxx.heap > xx.pdf

Locate the approximate memory leak point by comparing the two pdf. Check the process code to verify.

Summary:

1. When the memory pool is abused, the new is used when applying, and the recycling is left to the memory pool to handle itself, resulting in the continuous expansion of the memory pool.

Solution: the memory pool method should be used together.

two。 Asynchronous invocation, carelessly undiminished reference.

Solution: carefully encode incRef corresponding to decRef and try not to quote large structures, which makes the leakage problem more serious.

This is the end of the article on "sample analysis of server memory leaks". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report