Skip to content

Commit

Permalink
fix: lower memory usage a bit by disabling memory profiling
Browse files Browse the repository at this point in the history
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 <smirnov.andrey@gmail.com>
  • Loading branch information
smira authored and talos-bot committed Feb 1, 2021
1 parent 1cded4d commit 512c79e
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/app/apid/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"flag"
"log"
"regexp"
"runtime"
"strings"

"github.com/talos-systems/grpc-proxy/proxy"
Expand All @@ -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")
Expand Down
6 changes: 6 additions & 0 deletions internal/app/init/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"log"
"os"
"os/signal"
"runtime"
"syscall"
"time"

Expand All @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions internal/app/machined/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"net/url"
"os"
"os/signal"
goruntime "runtime"
"syscall"
"time"

Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions internal/app/networkd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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()
Expand Down
6 changes: 6 additions & 0 deletions internal/app/routerd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package main

import (
"log"
"runtime"

"github.com/talos-systems/grpc-proxy/proxy"
"google.golang.org/grpc"
Expand All @@ -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)

Expand Down
4 changes: 4 additions & 0 deletions internal/app/timed/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions internal/app/trustd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"flag"
"log"
stdlibnet "net"
"runtime"

"github.com/talos-systems/crypto/tls"
"github.com/talos-systems/net"
Expand All @@ -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()
Expand Down

0 comments on commit 512c79e

Please sign in to comment.