gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
75.82k stars 7.54k forks source link

Request String + Data Non-Caching Templating Partial Function #11154

Closed hollowaykeanho closed 7 months ago

hollowaykeanho commented 1 year ago

Request

Basically to replace this:

        {{- $filename = printf "deletable-%v-%v-%v-%v"
                                (mod (add (mul 13 now.Unix) 97) 400000)
                                (sha256 (string $Page.URL.Current.Absolute))
                                (now.Format "200601021504050700")
                                (crypto.FNV32a $dataList)
        -}}
        {{- $dataList = resources.FromString $filename $dataList -}}
        {{- $dataList = resources.ExecuteAsTemplate $filename $Page $dataList -}}
        {{- $dataList = string $dataList.Content -}}

Reason

  1. Existing solution is causing a "memory leak" phenomenon and no tool is available for investigation (see discource: https://discourse.gohugo.io/t/how-to-memory-profile-in-hugo-server/44728/1) and GitHub Issue https://github.com/ZORALab/Hestia/issues/106.
  2. This function is so powerful that it eliminates the need of shortcode and markdown layers of rendering entirely which speeds up and simplify the content generation process. The only problem with this is its undesirable auto-caching nature. (see discource: https://discourse.gohugo.io/t/how-to-instruct-hugo-pipe-not-to-cache/44467/6).

Severity

The memory leak phenomeon can occupy all the memory space and even get into swap. The only way to use is to periodically kill hugo server and restart it.

bep commented 1 year ago

I have no idea what this issue is about, so you need to make it more clear with some examples. And please inline them and not link to some discussion somewhere on the internet.

hollowaykeanho commented 1 year ago

Basically, I'm requesting a partial function that is doing a Go template function against a given string, returning a string, without caching. Right now, I'm using hugo pipe to do the work as shown above.

The problem is hugo pipe did unnecessary caching and somehow the caches are not released back to garbage collector even hitting the 10 minutes marker, behaving like a "memory leak" seen in C language. It doesn't matter how big your computer's RAM is, it will occupy all the RAM as garbage collector can't recover those unused memory.

We're looking at 21%, then 46%, then 72%, then 100% of 16GB Memory, and then enter swap. hugo-01

I detected there is a memory related issue here (Go programming language can't possibly "memory leak"). However, as presented in the Discourse discussion, I was not approached by anyone about any usable diagnostic tools to further root cause the problem.

I'm pretty sure it is Hugo Pipe because unfortunately, due to this issue, I was forced to stripped off quite a number of features (auto PWA caching, and etc). Hence, the entire theme is not using partialCached or .Store persistent scratchpad.

Reference function: https://github.com/ZORALab/Hestia/blob/experimental/hestiaHUGO/layouts/partials/hestiaSTRING/Sanitize


Value wise

This function itself can handle string rendering with Go templating which is very powerful that it can remove the need of using Markdown and hugo speicfic shortcode which behaves like partial. So, with this function, the theme developer can only focus on partial functions and create a Go compatible codes that are reusable elsewhere.

I just pre-launch an outcome of my approach here: https://hestia.zoralab.com/ which proven that this vital function can indeed build good Hugo theme products.


Use Example

Something like Strings.Process (I made this up) :

      {{- $Page := ... some dictionary data -}}

      {{- $ret := Strings.Process $Page "This page is: {{ .Page.Permalink -}}" -}}

      {{- warnf "%v\n" $ret -}}
----
The page is: http://localhost:8080/
----

Instead of:

        {{- $Page := ... some dictionary data -}}

        {{- $ret :=  "This page is: {{ .Page.Permalink -}}" -}}
        {{- $filename = printf "deletable-%v-%v-%v-%v"
                                (mod (add (mul 13 now.Unix) 97) 400000)
                                (sha256 (string $Page.URL.Current.Absolute))
                                (now.Format "200601021504050700")
                                (crypto.FNV32a $ret)
        -}}
        {{- $ret = resources.FromString $filename $ret -}}
        {{- $ret = resources.ExecuteAsTemplate $filename $Page $ret -}}
        {{- $ret = string $ret.Content -}}
        {{- warnf "%v\n" $ret -}}
----
The page is: http://localhost:8080/
----
hollowaykeanho commented 7 months ago

Close this ticket since I'm no longer deploying Hugo.

github-actions[bot] commented 6 months ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.