MCPcopy
hub / github.com/grafana/tempo / InitAutoMemLimit

Function InitAutoMemLimit

cmd/tempo/app/automemlimit.go:14–37  ·  view source on GitHub ↗

InitAutoMemLimit configures Go's memory limit using automemlimit based on the provided config. It is exported so that downstream consumers can call it.

(config *Config)

Source from the content-addressed store, hash-verified

12// InitAutoMemLimit configures Go's memory limit using automemlimit based on the
13// provided config. It is exported so that downstream consumers can call it.
14func InitAutoMemLimit(config *Config) {
15 if !config.Memory.AutoMemLimitEnabled {
16 return
17 }
18
19 logger := slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelInfo}))
20
21 limit, err := memlimit.SetGoMemLimitWithOpts(
22 memlimit.WithRatio(config.Memory.AutoMemLimitRatio),
23 memlimit.WithProvider(
24 memlimit.ApplyFallback(
25 memlimit.FromCgroup,
26 memlimit.FromSystem,
27 ),
28 ),
29 memlimit.WithRefreshInterval(15*time.Second),
30 memlimit.WithLogger(logger),
31 )
32 if err != nil {
33 fmt.Fprintf(os.Stderr, "warning: failed to set GOMEMLIMIT: %v\n", err)
34 return
35 }
36 fmt.Fprintf(os.Stderr, "info: GOMEMLIMIT set to %d bytes (ratio: %.2f)\n", limit, config.Memory.AutoMemLimitRatio)
37}

Callers 1

mainFunction · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected