Added function to improve CPU performance via GOMAXPROCS.

This commit is contained in:
Adrian Gallagher
2015-04-08 21:14:55 +10:00
parent 177f755abd
commit f73484800c

24
main.go
View File

@@ -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)