From ddca34f9e8cae564826e6b46b38342a9c1d8b4bf Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sun, 29 Mar 2020 12:31:17 -0700 Subject: [PATCH] Add support for defining specific threads for containers --- installer/installer.go | 2 +- server/environment_docker.go | 1 + server/server.go | 5 ++++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/installer/installer.go b/installer/installer.go index d656f10..4ee7f32 100644 --- a/installer/installer.go +++ b/installer/installer.go @@ -40,6 +40,7 @@ func New(data []byte) (*Installer, error) { IoWeight: uint16(getInt(data, "build", "io")), CpuLimit: getInt(data, "build", "cpu"), DiskSpace: getInt(data, "build", "disk"), + Threads: getString(data, "build", "threads"), }, Allocations: server.Allocations{ Mappings: make(map[string][]int), @@ -115,7 +116,6 @@ func (i *Installer) Execute() { return } - zap.S().Debugw("creating required environment for server instance", zap.String("server", i.Uuid())) if err := i.server.Environment.Create(); err != nil { zap.S().Errorw("failed to create environment for server", zap.String("server", i.Uuid()), zap.Error(err)) diff --git a/server/environment_docker.go b/server/environment_docker.go index 694a2a3..76c19fe 100644 --- a/server/environment_docker.go +++ b/server/environment_docker.go @@ -817,5 +817,6 @@ func (d *DockerEnvironment) getResourcesForServer() container.Resources { CPUShares: 1024, BlkioWeight: d.Server.Build.IoWeight, OomKillDisable: &d.Server.Container.OomDisabled, + CpusetCpus: d.Server.Build.Threads, } } diff --git a/server/server.go b/server/server.go index 491ecf3..7b9f37e 100644 --- a/server/server.go +++ b/server/server.go @@ -98,6 +98,9 @@ type BuildSettings struct { // The amount of disk space in megabytes that a server is allowed to use. DiskSpace int64 `json:"disk_space" yaml:"disk"` + + // Sets which CPU threads can be used by the docker instance. + Threads string `json:"threads" yaml:"threads"` } // Converts the CPU limit for a server build into a number that can be better understood @@ -294,7 +297,7 @@ func (s *Server) Sync() error { } // Update the data structure and persist it to the disk. - if err:= s.UpdateDataStructure(cfg.Settings, false); err != nil { + if err := s.UpdateDataStructure(cfg.Settings, false); err != nil { return errors.WithStack(err) }