当前位置:网站首页>Troubleshoot the high memory consumption of Go program
Troubleshoot the high memory consumption of Go program
2022-06-24 04:04:00 【Wangxiaoming_ HIT】
Download test code
go get You can get the test program , Pay attention to add -d Avoid automatic installation after downloading .
go get -d github.com/wolfogre/go-pprof-practice cd $GOPATH/src/github.com/wolfogre/go-pprof-practice
If go get Can't download , Sure git clone download
git clone https://github.com/wolfogre/go-pprof-practice
Compile the code
And then run
go mod init go mod tidy
Last run
go build ./go-pprof-practice
function pprof command
go tool pprof http://localhost:6060/debug/pprof/heap
Insert picture description here
Or three board axe top, list Wait for the order
list command
You can see that the problem is github.com/wolfogre/go-pprof-practice/animal/muridae/mouse.(*Mouse).Steal, The function looks like this :
func (m *Mouse) Steal() {
log.Println(m.Name(), "steal")
max := constant.Gi
for len(m.buffer) * constant.Mi < max {
m.buffer = append(m.buffer, [constant.Mi]byte{})
}
} You can see , There's a cycle going all the way to m.buffer The additional length is 1 MiB Array of , Until the total capacity reaches 1 GiB until , And never release these memory , No wonder there is such a high memory footprint . Use web To see a graphical presentation , It can be confirmed again that the problem is really here :
Welcome to the official account : The path of programmer wealth and freedom
Reference material
- https://blog.wolfogre.com/posts/go-ppof-practice/#%E6%8E%92%E6%9F%A5-cpu-%E5%8D%A0%E7%94%A8%E8%BF%87%E9%AB%98
边栏推荐
- Download files and close the enhanced module security configuration to visit the website for the first time using IE browser
- How to monitor multiple platforms simultaneously when easydss/easygbs platform runs real-time monitoring?
- Pycharm from installation to full armament
- What is FTP? What is the FTP address of the ECS?
- How to spell the iframe address of the video channel in easycvr?
- openEuler Kernel 技术分享第 20 期 | 执行实体创建与切换
- Black hat actual combat SEO: never be found hijacking
- Maintain the visibility of data automation: logging, auditing and error handling of the bridge of knowledge and action
- How should the server be placed?
- API real-time signature scheme based on Yapi
猜你喜欢

Pine Script脚本常用内容

openGauss 3.0版本源码编译安装指南

共建欧拉社区 共享欧拉生态|携手麒麟软件 共创数智未来

Brief ideas and simple cases of JVM tuning - how to tune
![[Numpy] Numpy对于NaN值的判断](/img/aa/dc75a86bbb9f5a235b1baf5f3495ff.png)
[Numpy] Numpy对于NaN值的判断

Flutter series: offstage in flutter

ModStartCMS 主题入门开发教程

An accident caused by a MySQL misoperation, and the "high availability" cannot withstand it!

祝贺钟君成为 CHAOSS Metric Model 工作组的 Maintainer

多任务视频推荐方案,百度工程师实战经验分享
随机推荐
Black hat SEO practice: General 301 weight PR hijacking
C language linked list points to the next structure pointer, structure and its many small details
Web penetration test - 5. Brute force cracking vulnerability - (4) telnet password cracking
Optimization of digital transformation management of procurement platform in construction industry
golang clean a slice
How to do the right thing in digital marketing of consumer goods enterprises?
Analysis of grafana SSO authentication process based on keyloak
How to bypass CDN to get web pages? How many options are available?
Discussion on the introduction principle and practice of fuzzy testing
祝贺钟君成为 CHAOSS Metric Model 工作组的 Maintainer
"." in the structure of C language And "- & gt;" Differences between
How should the server be placed?
[numpy] numpy's judgment on Nan value
Black hat SEO actual combat directory wheel chain generates millions of pages in batch
Dialogue with Google technical experts: soundstream is expected to be used for general audio coding in the future
How to restore the default route for Tencent cloud single network card machine
Demonstration of C language structure function research
What is a 1U server? What industries can 1U servers be used in?
flutter系列之:flutter中的offstage
抢先报名丨新一代 HTAP 数据库如何在云上重塑?TiDB V6 线上发布会即将揭晓!