Skip to content

Commit

Permalink
cmd/forwarder: add default GOMEMLIMIT
Browse files Browse the repository at this point in the history
Setting GOMEMLIMIT has very positive impact on the GC policy.
It allows to defer GC til there is less work.
In my tests, using local/browser tests with MITM, the Heap usage is bellow 40MiB and the system allocated memory bellow 100MiB at all times.
  • Loading branch information
mmatczuk committed Jan 5, 2024
1 parent 9229098 commit de05143
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
3 changes: 3 additions & 0 deletions cmd/forwarder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ func main() {
if _, err := maxprocs.Set(maxprocs.Logger(nil)); err != nil {
fmt.Fprintf(os.Stderr, "failed to set GOMAXPROCS: %v\n", err)
}
if _, ok := os.LookupEnv("GOMEMLIMIT"); !ok {
os.Setenv("GOMEMLIMIT", "250MiB")
}

if err := forwarder.Command().Execute(); err != nil {
os.WriteFile("/dev/termination-log", []byte(err.Error()), 0o644) //nolint // best effort
Expand Down
6 changes: 1 addition & 5 deletions command/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,7 @@ func (c *command) runE(cmd *cobra.Command, _ []string) (cmdErr error) {
}()

logger.Infof("Forwarder %s (%s)", version.Version, version.Commit)
if limit, ok := os.LookupEnv("GOMEMLIMIT"); ok {
logger.Debugf("resource limits: GOMAXPROCS=%d GOMEMLIMIT=%s", runtime.GOMAXPROCS(0), limit)
} else {
logger.Debugf("resource limits: GOMAXPROCS=%d", runtime.GOMAXPROCS(0))
}
logger.Debugf("resource limits: GOMAXPROCS=%d GOMEMLIMIT=%s", runtime.GOMAXPROCS(0), os.Getenv("GOMEMLIMIT"))

var ep []forwarder.APIEndpoint

Expand Down

0 comments on commit de05143

Please sign in to comment.