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:
parent
236b10a1a1
commit
98da370173
1 changed files with 24 additions and 0 deletions
|
@ -8,6 +8,9 @@ import (
|
|||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime/debug"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/fsnotify/fsnotify"
|
||||
|
@ -145,6 +148,23 @@ func (s *Server) Shutdown() error {
|
|||
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
|
||||
func New(config *Config) (*Server, error) {
|
||||
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.cleanupSandboxesOnShutdown()
|
||||
|
||||
|
|
Loading…
Reference in a new issue