A Ip2long function, by calling Go tool pprof analysis, unexpectedly found that memory allocated 3G

Source: Internet
Author: User
This is a created article in which the information may have evolved or changed.

Because IP storage, the need to convert the IP into an integer, so that more space-saving, while searching relatively fast, so the code needs a Ip2long function. The project is a background to perform the task, constantly accept requests, warehousing. Google for a while, on the internet to find a Golang version of the Ip2long code, is used in the project, the code is as follows:


Project in the intranet stress test process, found that after a few hours of execution, the process becomes a zombie process, the process has been there, but it is not found in processing data. Once the process is restarted, the data can be processed again. The first estimate may be a deadlock, the process has been waiting, looking for a long time, did not find the problem. Suddenly to see the memory footprint of the process, found up to 4-5g, and memory has been increasing, the initial estimate is a memory leak it. Go tool pprof analysis found this function memory consumption super High:


Very strange, why is a regular memory consumption so high?

Modify the Ip2long function as follows:


Run the program again, after a while to find that the memory consumption is not so high! Is there a memory leak in the Golang version of the recumbent slot? How can a regular memory footprint be that high?




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.