From ec046ad1203dda609173f4d8410669ee50633ce2 Mon Sep 17 00:00:00 2001 From: Javier Palomo Date: Fri, 28 Jan 2022 14:15:28 +0100 Subject: [PATCH 1/2] tk/export: introduce a configurable memory ballast --- cmd/tk/export.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cmd/tk/export.go b/cmd/tk/export.go index 1b7460aa5..ee663541d 100644 --- a/cmd/tk/export.go +++ b/cmd/tk/export.go @@ -3,6 +3,7 @@ package main import ( "fmt" "regexp" + "runtime" "github.com/go-clix/cli" @@ -37,6 +38,7 @@ func exportCmd() *cli.Command { parallel := cmd.Flags().IntP("parallel", "p", 8, "Number of environments to process in parallel") cachePath := cmd.Flags().StringP("cache-path", "c", "", "Local file path where cached evaluations should be stored") cacheEnvs := cmd.Flags().StringArrayP("cache-envs", "e", nil, "Regexes which define which environment should be cached (if caching is enabled)") + ballastBytes := cmd.Flags().Int("mem-ballast-size-bytes", 0, "Size of memory ballast to allocate.") vars := workflowFlags(cmd.Flags()) getJsonnetOpts := jsonnetFlags(cmd.Flags()) @@ -45,6 +47,10 @@ func exportCmd() *cli.Command { recursive := cmd.Flags().BoolP("recursive", "r", false, "Look recursively for Tanka environments") cmd.Run = func(cmd *cli.Command, args []string) error { + // Allocate a block of memory to alter GC behaviour. See https://github.com/golang/go/issues/23044 + ballast := make([]byte, *ballastBytes) + defer runtime.KeepAlive(ballast) + filters, err := process.StrExps(vars.targets...) if err != nil { return err From 2817b1918c4a97c0eefcae62074fc1183c026083 Mon Sep 17 00:00:00 2001 From: Javier Palomo Date: Mon, 31 Jan 2022 16:19:08 +0100 Subject: [PATCH 2/2] tk/export: hide the ballast flag To signal that this is intended for experimental purposes. --- cmd/tk/export.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cmd/tk/export.go b/cmd/tk/export.go index ee663541d..68ece5d80 100644 --- a/cmd/tk/export.go +++ b/cmd/tk/export.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "log" "regexp" "runtime" @@ -38,7 +39,11 @@ func exportCmd() *cli.Command { parallel := cmd.Flags().IntP("parallel", "p", 8, "Number of environments to process in parallel") cachePath := cmd.Flags().StringP("cache-path", "c", "", "Local file path where cached evaluations should be stored") cacheEnvs := cmd.Flags().StringArrayP("cache-envs", "e", nil, "Regexes which define which environment should be cached (if caching is enabled)") - ballastBytes := cmd.Flags().Int("mem-ballast-size-bytes", 0, "Size of memory ballast to allocate.") + + ballastBytes := cmd.Flags().Int("mem-ballast-size-bytes", 0, "(Experimental) Size of memory ballast to allocate.") + if err := cmd.Flags().MarkHidden("mem-ballast-size-bytes"); err != nil { + log.Fatalf("Could not mark flag as hidden: %s", err) + } vars := workflowFlags(cmd.Flags()) getJsonnetOpts := jsonnetFlags(cmd.Flags())