0

I am running go application and use pprof to get heap profile of it as below:

curl -s http://localhost:<port>/debug/pprof/heap > heap_profile.out
go tool pprof heap_profile.out

As a result, I get this: Showing nodes accounting for 507.98MB, 99.41% of 510.98MB total. But I don't know where does it get this 507.98MB in first place. When I check current memory usage using top, it shows that my application is using only 200MB memory (RES value in top command's result). Can somebody explain what is the difference between total in_use memory shown by heap profile and mem_usage given by top ?

Rohanil
  • 1,717
  • 5
  • 22
  • 47
  • What OS are you on? I'm not familiar with a `top` metric of `mem_usage` - typically you get separate metrics for virtual, shared, and resident memory, labelled `virt`, `shr`, and `res`, respectively. – Adrian Aug 30 '18 at 14:38
  • @Adrian it is LinuxOS and I am referring to RES value. – Rohanil Aug 30 '18 at 14:47
  • `pprof` is a profiler, it tells you about heap allocations over time. Most of that will have been garbage collected, not actively in use, and therefor not reflected in a point-in-time snapshot of memory usage like that found in top. – Adrian Aug 30 '18 at 14:51
  • I set env variable `GOGC=off` and restarted app and took heap profile. But there is still a difference and it is almost same. – Rohanil Aug 30 '18 at 14:55
  • I think this answers your question, it's in go [faq](https://golang.org/doc/faq#Why_does_my_Go_process_use_so_much_virtual_memory) – nilsocket Aug 30 '18 at 15:27
  • @nilsocket question is about resident memory, not virtual memory. Also it's about heap profiler showing *more* memory used than shown in top, not less. – Adrian Aug 30 '18 at 15:41

0 Answers0