Golang性能分析AppEngine测试

huangapple go评论87阅读模式
英文:

Golang profiling appengine tests

问题

我似乎遇到了一个与接收大文件并将其发送到GCS相关的内存泄漏问题。我正在尝试使用pprof来对我的appengine代码进行内存使用情况进行分析。我的测试使用了appengine/aetest,并且我可以输出内存配置文件,但结果似乎没有显示出有用的信息。

首先,我创建了一个基准测试。这是一个非常慢的操作,所以只运行一次。

$ goapp test ./cloudstore -run=none -bench=. -memprofile=cloud.prof
BenchmarkLargeFile      1        54124706398 ns/op

$ go tool pprof --text cloudstore.test cloud.prof 
Adjusting heap profiles for 1-in-524288 sampling rate
Total: 0.5 MB
     0.5 100.0% 100.0%      0.5 100.0% runtime.newG
     0.0   0.0% 100.0%      0.5 100.0% allocg
     0.0   0.0% 100.0%      0.5 100.0% mcommoninit
     0.0   0.0% 100.0%      0.5 100.0% runtime.malg
     0.0   0.0% 100.0%      0.5 100.0% runtime.mpreinit
     0.0   0.0% 100.0%      0.5 100.0% runtime.rt0_go
     0.0   0.0% 100.0%      0.5 100.0% runtime.schedinit

我的函数调用都没有显示出来,而且这个0.5 MB的数字显然是不正确的(我正在打开一个12 MB的文件并上传它)。我该如何获取真实的内存配置文件?

$ go version
go version go1.3.1 linux/386
$ goapp version
go version go1.4.2 (appengine-1.9.25) linux/386
英文:

I appear to have a memory leak related to receiving large files and sending them to GCS. Trying to use pprof to profile memory usage for my appengine code. My tests use appengine/aetest and I can output the memory profile, but the results don't seem to show me anything useful.

First I made a benchmark. It is a very slow operation, so it only runs once.

$ goapp test ./cloudstore -run=none -bench=. -memprofile=cloud.prof
BenchmarkLargeFile      1        54124706398 ns/op

$ go tool pprof --text cloudstore.test cloud.prof 
Adjusting heap profiles for 1-in-524288 sampling rate
Total: 0.5 MB
     0.5 100.0% 100.0%      0.5 100.0% runtime.newG
     0.0   0.0% 100.0%      0.5 100.0% allocg
     0.0   0.0% 100.0%      0.5 100.0% mcommoninit
     0.0   0.0% 100.0%      0.5 100.0% runtime.malg
     0.0   0.0% 100.0%      0.5 100.0% runtime.mpreinit
     0.0   0.0% 100.0%      0.5 100.0% runtime.rt0_go
     0.0   0.0% 100.0%      0.5 100.0% runtime.schedinit

None of my function calls appear and this 0.5 MB figure is obviously incorrect (I am opening a 12 MB file and uploading it). How do I get the real memory profile?

$ go version
go version go1.3.1 linux/386
$ goapp version
go version go1.4.2 (appengine-1.9.25) linux/386

答案1

得分: 0

深入研究了测试标志,我找到了答案。我需要使用memprofilerate=1和alloc_space。

$ goapp test ./cloudstore -memprofilerate=1 -run=none -bench=. -memprofile=cloud.prof
$ go tool pprof --text --alloc_space cloudstore.test cloud.prof
英文:

Dug deeper into the testing flags and I found the answer. I needed memprofilerate=1 and alloc_space

$ goapp test ./cloudstore -memprofilerate=1 -run=none -bench=. -memprofile=cloud.prof
$ go tool pprof --text --alloc_space cloudstore.test cloud.prof

huangapple
  • 本文由 发表于 2015年11月13日 04:05:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/33680353.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定