mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
Added function to improve CPU performance via GOMAXPROCS.
This commit is contained in:
24
main.go
24
main.go
@@ -6,6 +6,8 @@ import (
|
||||
"errors"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"strconv"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
type Exchange struct {
|
||||
@@ -59,6 +61,8 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
AdjustGoMaxProcs()
|
||||
|
||||
smsSupport := false
|
||||
smsContacts := 0
|
||||
|
||||
@@ -250,6 +254,26 @@ func main() {
|
||||
Shutdown()
|
||||
}
|
||||
|
||||
func AdjustGoMaxProcs() {
|
||||
log.Println("Adjusting bot runtime performance..")
|
||||
maxProcsEnv := os.Getenv("GOMAXPROCS")
|
||||
maxProcs := runtime.NumCPU()
|
||||
log.Println("Number of CPU's detected:", maxProcs)
|
||||
|
||||
if maxProcsEnv != "" {
|
||||
log.Println("GOMAXPROCS env =", maxProcsEnv)
|
||||
env, err := strconv.Atoi(maxProcsEnv)
|
||||
|
||||
if err != nil {
|
||||
log.Println("Unable to convert GOMAXPROCS to int, using", maxProcs)
|
||||
} else {
|
||||
maxProcs = env
|
||||
}
|
||||
}
|
||||
log.Println("Set GOMAXPROCS to:", maxProcs)
|
||||
runtime.GOMAXPROCS(maxProcs)
|
||||
}
|
||||
|
||||
func HandleInterrupt() {
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||
|
||||
Reference in New Issue
Block a user