From 512c79e8d646f38699f7cb69e99d7a1643d86f8a Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Mon, 1 Feb 2021 15:24:52 +0300 Subject: [PATCH] fix: lower memory usage a bit by disabling memory profiling As of now, we're not using Go profiling, so it's safe to disable it to save some memory and CPU costs. Once we start using it, we can re-enable it conditionally. Each process allocates around 1.4MiB on amd64 for memory profiling buckets. Signed-off-by: Andrey Smirnov --- internal/app/apid/main.go | 4 ++++ internal/app/init/main.go | 6 ++++++ internal/app/machined/main.go | 4 ++++ internal/app/networkd/main.go | 4 ++++ internal/app/routerd/main.go | 6 ++++++ internal/app/timed/main.go | 4 ++++ internal/app/trustd/main.go | 4 ++++ 7 files changed, 32 insertions(+) diff --git a/internal/app/apid/main.go b/internal/app/apid/main.go index a92d9c108..84ff5e55f 100644 --- a/internal/app/apid/main.go +++ b/internal/app/apid/main.go @@ -8,6 +8,7 @@ import ( "flag" "log" "regexp" + "runtime" "strings" "github.com/talos-systems/grpc-proxy/proxy" @@ -28,6 +29,9 @@ import ( var endpoints *string func init() { + // Explicitly disable memory profiling to save around 1.4MiB of memory. + runtime.MemProfileRate = 0 + log.SetFlags(log.Lshortfile | log.Ldate | log.Lmicroseconds | log.Ltime) endpoints = flag.String("endpoints", "", "the IPs of the control plane nodes") diff --git a/internal/app/init/main.go b/internal/app/init/main.go index c84552bc6..dba2b010c 100644 --- a/internal/app/init/main.go +++ b/internal/app/init/main.go @@ -10,6 +10,7 @@ import ( "log" "os" "os/signal" + "runtime" "syscall" "time" @@ -23,6 +24,11 @@ import ( "github.com/talos-systems/talos/pkg/version" ) +func init() { + // Explicitly disable memory profiling to save around 1.4MiB of memory. + runtime.MemProfileRate = 0 +} + func run() (err error) { // Mount the pseudo devices. pseudo, err := mount.PseudoMountPoints() diff --git a/internal/app/machined/main.go b/internal/app/machined/main.go index 8da795b5b..1171a1892 100644 --- a/internal/app/machined/main.go +++ b/internal/app/machined/main.go @@ -14,6 +14,7 @@ import ( "net/url" "os" "os/signal" + goruntime "runtime" "syscall" "time" @@ -36,6 +37,9 @@ import ( ) func init() { + // Explicitly disable memory profiling to save around 1.4MiB of memory. + goruntime.MemProfileRate = 0 + // Explicitly set the default http client transport to work around proxy.Do // once. This is the http.DefaultTransport with the Proxy func overridden so // that the environment variables with be reread/initialized each time the diff --git a/internal/app/networkd/main.go b/internal/app/networkd/main.go index b96d38bb1..9847bd96b 100644 --- a/internal/app/networkd/main.go +++ b/internal/app/networkd/main.go @@ -7,6 +7,7 @@ package main import ( "flag" "log" + "runtime" "github.com/talos-systems/talos/internal/app/networkd/pkg/networkd" "github.com/talos-systems/talos/internal/app/networkd/pkg/reg" @@ -16,6 +17,9 @@ import ( ) func init() { + // Explicitly disable memory profiling to save around 1.4MiB of memory. + runtime.MemProfileRate = 0 + log.SetFlags(log.Lshortfile | log.Ldate | log.Lmicroseconds | log.Ltime) flag.Parse() diff --git a/internal/app/routerd/main.go b/internal/app/routerd/main.go index 3a358e7b1..d077943d2 100644 --- a/internal/app/routerd/main.go +++ b/internal/app/routerd/main.go @@ -6,6 +6,7 @@ package main import ( "log" + "runtime" "github.com/talos-systems/grpc-proxy/proxy" "google.golang.org/grpc" @@ -17,6 +18,11 @@ import ( "github.com/talos-systems/talos/pkg/startup" ) +func init() { + // Explicitly disable memory profiling to save around 1.4MiB of memory. + runtime.MemProfileRate = 0 +} + func main() { log.SetFlags(log.Lshortfile | log.Ldate | log.Lmicroseconds | log.Ltime) diff --git a/internal/app/timed/main.go b/internal/app/timed/main.go index 2d86dc0c0..4a0f3565e 100644 --- a/internal/app/timed/main.go +++ b/internal/app/timed/main.go @@ -7,6 +7,7 @@ package main import ( "flag" "log" + "runtime" "github.com/talos-systems/talos/internal/app/timed/pkg/ntp" "github.com/talos-systems/talos/internal/app/timed/pkg/reg" @@ -26,6 +27,9 @@ const ( ) func init() { + // Explicitly disable memory profiling to save around 1.4MiB of memory. + runtime.MemProfileRate = 0 + log.SetFlags(log.Lshortfile | log.Ldate | log.Lmicroseconds | log.Ltime) flag.Parse() diff --git a/internal/app/trustd/main.go b/internal/app/trustd/main.go index 053daeb08..56fcbc77e 100644 --- a/internal/app/trustd/main.go +++ b/internal/app/trustd/main.go @@ -8,6 +8,7 @@ import ( "flag" "log" stdlibnet "net" + "runtime" "github.com/talos-systems/crypto/tls" "github.com/talos-systems/net" @@ -24,6 +25,9 @@ import ( ) func init() { + // Explicitly disable memory profiling to save around 1.4MiB of memory. + runtime.MemProfileRate = 0 + log.SetFlags(log.Lshortfile | log.Ldate | log.Lmicroseconds | log.Ltime) flag.Parse()