server: set golang runtime max threads

SetMaxThreads from runtime/debug in Golang is called to set max threads
value to 90% of /proc/sys/kernel/threads-max
Should really help performance.

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
Antonio Murdaca 2017-08-23 19:35:06 +02:00
parent 236b10a1a1
commit 98da370173
No known key found for this signature in database
GPG key ID: B2BEAD150DE936B9

View file

@ -8,6 +8,9 @@ import (
"net/http" "net/http"
"os" "os"
"path/filepath" "path/filepath"
"runtime/debug"
"strconv"
"strings"
"sync" "sync"
"github.com/fsnotify/fsnotify" "github.com/fsnotify/fsnotify"
@ -145,6 +148,23 @@ func (s *Server) Shutdown() error {
return s.ContainerServer.Shutdown() return s.ContainerServer.Shutdown()
} }
// configureMaxThreads sets the Go runtime max threads threshold
// which is 90% of the kernel setting from /proc/sys/kernel/threads-max
func configureMaxThreads() error {
mt, err := ioutil.ReadFile("/proc/sys/kernel/threads-max")
if err != nil {
return err
}
mtint, err := strconv.Atoi(strings.TrimSpace(string(mt)))
if err != nil {
return err
}
maxThreads := (mtint / 100) * 90
debug.SetMaxThreads(maxThreads)
logrus.Debugf("Golang's threads limit set to %d", maxThreads)
return nil
}
// New creates a new Server with options provided // New creates a new Server with options provided
func New(config *Config) (*Server, error) { func New(config *Config) (*Server, error) {
if err := os.MkdirAll("/var/run/crio", 0755); err != nil { if err := os.MkdirAll("/var/run/crio", 0755); err != nil {
@ -199,6 +219,10 @@ func New(config *Config) (*Server, error) {
} }
} }
if err := configureMaxThreads(); err != nil {
return nil, err
}
s.restore() s.restore()
s.cleanupSandboxesOnShutdown() s.cleanupSandboxesOnShutdown()