How to measure memory usage?

Is there a way to measure memory usage with Hugo?

That would be ideal to find potential memory spikes in themes etc…

Thanks a lot!

I added a lot of cool profiling stuff in Hugo 0.54, sadly the mem profiling implementation was a little hasty. Fixed in:

With that you can do:

hugo --profile-mem mem.prof

And do:

go tool pprof --alloc_space mem.prof

And then maybe type top:

Showing top 10 nodes out of 111
      flat  flat%   sum%        cum   cum%
 1682.94MB 58.77% 58.77%  1682.94MB 58.77%  github.com/nicksnyder/go-i18n/i18n/bundle.(*Bundle).Translations
  235.51MB  8.22% 67.00%  2265.16MB 79.11%  reflect.Value.call
   80.01MB  2.79% 69.79%    80.01MB  2.79%  text/template/parse.(*Tree).newPipeline
   56.01MB  1.96% 71.75%    56.01MB  1.96%  reflect.FuncOf
   51.50MB  1.80% 73.55%    51.50MB  1.80%  text/template/parse.(*CommandNode).append
   47.96MB  1.68% 75.22%    47.96MB  1.68%  bytes.makeSlice
   43.50MB  1.52% 76.74%    56.50MB  1.97%  reflect.MakeSlice

The above is from a real Hugo site, from which I found a bottleneck/bug that I will fix that will make the above site twice as fast.

I wrote this quickly, and omitted info about installing pprof etc.

I can add that the profiles you get is very much connected to the Hugo implementation, which may or may not be helpful.

2 Likes

To add to bep’s info, here’s a sample top command if you wanted to continuously monitor hugo server’s cpu% and memory usage

top -stats command,cpu,mem | grep hugo
2 Likes

Thanks a ton! All of this looks amazing.

Will take a deep look at this :dark_sunglasses: .

There’s also

hugo server --memstats mystats.txt
1 Like

What is hugo server --memstats mystats.txt supposed to output?
Does it only log memory usage for specific actions taken on the web? I am asking because I am unable to get memstats to output anything useful on my local instance. (Hugo v0.55.5 for context)