mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 16:59:12 +00:00
feat(runtime): Set GOMEMLIMIT from environment (#1821)
* feat(runtime): Set GOMEMLIMIT from environment * feat: log memlimit err * feat: go mod tidy --------- Co-authored-by: ze0s <ze0s@riseup.net>
This commit is contained in:
parent
7888ea3ae5
commit
b17e586d63
3 changed files with 40 additions and 5 deletions
|
@ -35,6 +35,7 @@ import (
|
|||
"github.com/autobrr/autobrr/internal/update"
|
||||
"github.com/autobrr/autobrr/internal/user"
|
||||
|
||||
"github.com/KimMachineGun/automemlimit/memlimit"
|
||||
"github.com/asaskevich/EventBus"
|
||||
"github.com/dcarbone/zadapters/zstdlog"
|
||||
"github.com/r3labs/sse/v2"
|
||||
|
@ -55,7 +56,7 @@ func main() {
|
|||
pflag.StringVar(&profilePath, "pgo", "", "internal build flag")
|
||||
pflag.Parse()
|
||||
|
||||
shutdownFunc := pgoRun(profilePath)
|
||||
shutdownFunc, isPGO := pgoRun(profilePath)
|
||||
|
||||
// read config
|
||||
cfg := config.New(configPath, version)
|
||||
|
@ -70,6 +71,12 @@ func main() {
|
|||
log.Error().Err(err).Msg("failed to set GOMAXPROCS")
|
||||
}
|
||||
|
||||
// Set GOMEMLIMIT to match the Linux container Memory quota (if any)
|
||||
memLimit, err := memlimit.SetGoMemLimitWithOpts(memlimit.WithProvider(memlimit.ApplyFallback(memlimit.FromCgroupHybrid, memlimit.FromSystem)))
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("failed to set GOMEMLIMIT")
|
||||
}
|
||||
|
||||
// init dynamic config
|
||||
cfg.DynamicReload(log)
|
||||
|
||||
|
@ -97,6 +104,7 @@ func main() {
|
|||
log.Info().Msgf("Build date: %s", date)
|
||||
log.Info().Msgf("Log-level: %s", cfg.Config.LogLevel)
|
||||
log.Info().Msgf("Using database: %s", db.Driver)
|
||||
log.Debug().Msgf("GOMEMLIMIT: %d bytes", memLimit)
|
||||
|
||||
// setup repos
|
||||
var (
|
||||
|
@ -173,7 +181,7 @@ func main() {
|
|||
return
|
||||
}
|
||||
|
||||
if shutdownFunc != nil {
|
||||
if isPGO {
|
||||
time.Sleep(5 * time.Second)
|
||||
sigCh <- syscall.SIGQUIT
|
||||
}
|
||||
|
@ -193,9 +201,9 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
func pgoRun(file string) func() {
|
||||
func pgoRun(file string) (func(), bool) {
|
||||
if len(file) == 0 {
|
||||
return nil
|
||||
return func() {}, false
|
||||
}
|
||||
|
||||
f, err := os.Create(file)
|
||||
|
@ -210,5 +218,5 @@ func pgoRun(file string) func() {
|
|||
return func() {
|
||||
defer f.Close()
|
||||
defer pprof.StopCPUProfile()
|
||||
}
|
||||
}, true
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue