当前位置:网站首页>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
边栏推荐
- Old popup explorer Exe has stopped working due to problems. What should I do?
- 系统的去学习一门编程语言,原来有如此捷径
- "The first share of Chinese member e-commerce" gathered in the anti reptile attack and defense war | talk with industrial security experts
- well! Do you want to have a romantic date with the shining "China Star"?
- Black hat SEO practice: General 301 weight PR hijacking
- [numpy] numpy's judgment on Nan value
- Modstartcms theme introductory development tutorial
- JVM调优简要思想及简单案例-怎么调优
- Modstartcms enterprise content site building system (supporting laravel9) v4.2.0
- Rasa 3. X learning series -rasa 3.2.0 new release
猜你喜欢

openEuler社区理事长江大勇:共推欧拉开源新模式 共建开源新体系

ClickHouse(02)ClickHouse架构设计介绍概述与ClickHouse数据分片设计

黑帽SEO实战搜索引擎快照劫持

Black hat SEO practice: General 301 weight PR hijacking

开源之夏2022中选结果公示,449名高校生将投入开源项目贡献

15+城市道路要素分割应用,用这一个分割模型就够了

Black hat actual combat SEO: never be found hijacking

Kubernetes 资源拓扑感知调度优化

Modstartcms theme introductory development tutorial

Pine Script脚本常用内容
随机推荐
Analysis of grafana SSO authentication process based on keyloak
黑帽SEO实战之通用301权重pr劫持
Cloud development CMS Enterprise Edition demand survey
[new light weight first purchase special] 1-core 2g5m light weight application server costs 50 yuan in the first year. It is cost-effective and helps you get on the cloud easily!
Modstartcms enterprise content site building system (supporting laravel9) v4.2.0
Halcon knowledge: contour operator on region (2)
Use the fluxbox desktop as your window manager
web rdp Myrtille
How to select a telemedicine program system? These four points are the key!
LeetCode 2006. Number of pairs whose absolute value of difference is k
How to be a web server and what are the advantages of a web server
Getlocationinwindow source code
Web penetration test - 5. Brute force cracking vulnerability - (4) telnet password cracking
golang clean a slice
How to save pictures to CDN? What are the advantages of this?
[Numpy] Numpy对于NaN值的判断
In the post epidemic era, "cloud live broadcast" saves "cloud cultural tourism"?
Diskpart San policy is not onlineall, which affects automatic disk hanging
[numpy] numpy's judgment on Nan value
How to bypass CDN to get web pages? How many options are available?