Skip to content

Commit

Permalink
feat: Optimize the use of gomaxprocs (#452)
Browse files Browse the repository at this point in the history
  • Loading branch information
B15030328 authored Sep 30, 2022
1 parent 6647ca1 commit 59ae1ea
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pkg/autoproc/autoproc.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ import (
)

func init() {
// 初始化注册中心
if _, err := maxprocs.Set(); err != nil {
xlog.Jupiter().Panic("auto max procs", xlog.FieldMod(ecode.ModProc), xlog.FieldErrKind(ecode.ErrKindAny), xlog.FieldErr(err))
}
// 初始化GOMAXPROCS
conf.OnLoaded(func(c *conf.Configuration) {
if maxProcs := conf.GetInt("maxProc"); maxProcs != 0 {
maxProcs := conf.GetInt("app.maxProc")
if maxProcs > 0 && maxProcs < runtime.NumCPU() {
runtime.GOMAXPROCS(maxProcs)
} else if _, err := maxprocs.Set(); err != nil {
xlog.Jupiter().Panic("auto max procs", xlog.FieldMod(ecode.ModProc), xlog.FieldErrKind(ecode.ErrKindAny), xlog.FieldErr(err))
}
xlog.Jupiter().Info("auto max procs", xlog.FieldMod(ecode.ModProc), xlog.Int64("procs", int64(runtime.GOMAXPROCS(-1))))
})
Expand Down

0 comments on commit 59ae1ea

Please sign in to comment.