mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-23 15:10:15 +00:00
Fix utils.AdjustGoMaxProcs
Since Go 1.5, Go will use the total number of logical processers that the system has available. Caveats to this are if someone has set the GOMAXPROCS env var set or wish to limit usage of the number of logical processers between a range from 1 to NumCPUs
This commit is contained in:
@@ -16,16 +16,29 @@ var (
|
||||
)
|
||||
|
||||
// AdjustGoMaxProcs sets the runtime GOMAXPROCS val
|
||||
func AdjustGoMaxProcs(maxProcs int) error {
|
||||
// Since Go 1.5, Go will use the total number of logical processers that the
|
||||
// system has available. Caveats to this are if someone has set the GOMAXPROCS
|
||||
// env var set or wish to limit usage of the number of logical processers
|
||||
// between a range from 1 to NumCPUs
|
||||
func AdjustGoMaxProcs(procs int) error {
|
||||
// Check for default settings, plus respecting GOMAXPROCS env but
|
||||
// don't allow for values which will cause thread contention
|
||||
n := runtime.NumCPU()
|
||||
if maxProcs < 0 || maxProcs > n {
|
||||
maxProcs = n
|
||||
if procs == runtime.GOMAXPROCS(-1) {
|
||||
if procs <= n {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
if i := runtime.GOMAXPROCS(maxProcs); i != maxProcs {
|
||||
// Sanitise the procs value (defaults to NumCPUs)
|
||||
if procs < 1 || procs > n {
|
||||
procs = n
|
||||
}
|
||||
|
||||
runtime.GOMAXPROCS(procs)
|
||||
if i := runtime.GOMAXPROCS(procs); i != procs {
|
||||
return ErrGoMaxProcsFailure
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user