aboutsummaryrefslogtreecommitdiffhomepage
path: root/commands
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2024-02-02 16:00:48 +0100
committerBjørn Erik Pedersen <[email protected]>2024-02-02 18:46:23 +0100
commit28733248983c1afc1e4e15dfc30fcf4c442e6ca4 (patch)
treef8680096a715dd88c5ad3f8de7d8f6fdde54faa8 /commands
parentd0788b96ae74eb2d48a75c7147e7c6a5457977da (diff)
downloadhugo-28733248983c1afc1e4e15dfc30fcf4c442e6ca4.tar.gz
hugo-28733248983c1afc1e4e15dfc30fcf4c442e6ca4.zip
Misc resource fixes/improvements
* Add --pprof flag to server to enable profile debugging. * Don't cache the resource content, it seem to eat memory on bigger sites. * Keep --printMemoryUsag running in server Fixes #11974
Diffstat (limited to 'commands')
-rw-r--r--commands/commandeer.go10
-rw-r--r--commands/hugobuilder.go20
-rw-r--r--commands/server.go14
3 files changed, 30 insertions, 14 deletions
diff --git a/commands/commandeer.go b/commands/commandeer.go
index 1aac08c42..0052d91b4 100644
--- a/commands/commandeer.go
+++ b/commands/commandeer.go
@@ -22,6 +22,7 @@ import (
"os"
"os/signal"
"path/filepath"
+ "runtime"
"strings"
"sync"
"sync/atomic"
@@ -341,8 +342,12 @@ func (r *rootCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, args
if r.buildWatch {
defer r.timeTrack(time.Now(), "Built")
}
- err := b.build()
- return err
+ close, err := b.build()
+ if err != nil {
+ return err
+ }
+ close()
+ return nil
}()
if err != nil {
return err
@@ -411,6 +416,7 @@ func (r *rootCommand) PreRun(cd, runner *simplecobra.Commandeer) error {
MaxEntries: 1,
OnEvict: func(key int32, value *hugolib.HugoSites) {
value.Close()
+ runtime.GC()
},
})
diff --git a/commands/hugobuilder.go b/commands/hugobuilder.go
index 41f42ae6d..ddc92129c 100644
--- a/commands/hugobuilder.go
+++ b/commands/hugobuilder.go
@@ -361,34 +361,32 @@ func (c *hugoBuilder) newWatcher(pollIntervalStr string, dirList ...string) (*wa
return watcher, nil
}
-func (c *hugoBuilder) build() error {
+func (c *hugoBuilder) build() (func(), error) {
stopProfiling, err := c.initProfiling()
if err != nil {
- return err
+ return nil, err
}
- defer func() {
- if stopProfiling != nil {
- stopProfiling()
- }
- }()
-
if err := c.fullBuild(false); err != nil {
- return err
+ return nil, err
}
if !c.r.quiet {
c.r.Println()
h, err := c.hugo()
if err != nil {
- return err
+ return nil, err
}
h.PrintProcessingStats(os.Stdout)
c.r.Println()
}
- return nil
+ return func() {
+ if stopProfiling != nil {
+ stopProfiling()
+ }
+ }, nil
}
func (c *hugoBuilder) buildSites(noBuildLock bool) (err error) {
diff --git a/commands/server.go b/commands/server.go
index 97cf405b7..574f5c340 100644
--- a/commands/server.go
+++ b/commands/server.go
@@ -25,6 +25,7 @@ import (
"io"
"net"
"net/http"
+ _ "net/http/pprof"
"net/url"
"os"
"os/signal"
@@ -451,6 +452,7 @@ type serverCommand struct {
tlsCertFile string
tlsKeyFile string
tlsAuto bool
+ pprof bool
serverPort int
liveReloadPort int
serverWatch bool
@@ -465,6 +467,11 @@ func (c *serverCommand) Name() string {
}
func (c *serverCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, args []string) error {
+ if c.pprof {
+ go func() {
+ http.ListenAndServe("localhost:8080", nil)
+ }()
+ }
// Watch runs its own server as part of the routine
if c.serverWatch {
@@ -487,15 +494,19 @@ func (c *serverCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, arg
}
+ var close func()
err := func() error {
defer c.r.timeTrack(time.Now(), "Built")
- err := c.build()
+ var err error
+ close, err = c.build()
return err
}()
if err != nil {
return err
}
+ defer close()
+
return c.serve()
}
@@ -520,6 +531,7 @@ of a second, you will be able to save and see your changes nearly instantly.`
cmd.Flags().StringVarP(&c.tlsCertFile, "tlsCertFile", "", "", "path to TLS certificate file")
cmd.Flags().StringVarP(&c.tlsKeyFile, "tlsKeyFile", "", "", "path to TLS key file")
cmd.Flags().BoolVar(&c.tlsAuto, "tlsAuto", false, "generate and use locally-trusted certificates.")
+ cmd.Flags().BoolVar(&c.pprof, "pprof", false, "enable the pprof server (port 8080)")
cmd.Flags().BoolVarP(&c.serverWatch, "watch", "w", true, "watch filesystem for changes and recreate as needed")
cmd.Flags().BoolVar(&c.noHTTPCache, "noHTTPCache", false, "prevent HTTP caching")
cmd.Flags().BoolVarP(&c.serverAppend, "appendPort", "", true, "append port to baseURL")