diff options
author | Aleksandr Razumov <ar@gortc.io> | 2019-12-15 20:57:23 +0300 |
---|---|---|
committer | Aleksandr Razumov <ar@gortc.io> | 2019-12-15 21:12:43 +0300 |
commit | 8782f0e287df2a2fd9f9dfb3f0e1589cc15a4f91 (patch) | |
tree | d08d7f3a04d700b2edc2538d80ef9d3f0137989c /runsc/sandbox/sandbox.go | |
parent | 6b424530397e5100b08628efe8f6c62178daa70b (diff) |
Set CPU number to CPU quota
When application is not cgroups-aware, it can spawn excessive threads
which often defaults to CPU number.
Introduce a opt-in flag that will set CPU number accordingly to CPU
quota (if available).
Fixes #1391
Diffstat (limited to 'runsc/sandbox/sandbox.go')
-rw-r--r-- | runsc/sandbox/sandbox.go | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/runsc/sandbox/sandbox.go b/runsc/sandbox/sandbox.go index 805233184..cbfb873d1 100644 --- a/runsc/sandbox/sandbox.go +++ b/runsc/sandbox/sandbox.go @@ -18,6 +18,7 @@ package sandbox import ( "context" "fmt" + "math" "os" "os/exec" "strconv" @@ -631,6 +632,15 @@ func (s *Sandbox) createSandboxProcess(conf *boot.Config, args *Args, startSyncF if err != nil { return fmt.Errorf("getting cpu count from cgroups: %v", err) } + if conf.CPUNumFromQuota { + quota, err := s.Cgroup.CPUQuota() + if err != nil { + return fmt.Errorf("getting cpu qouta from cgroups: %v", err) + } + if quota > 0 { + cpuNum = int(math.Ceil(quota)) + } + } cmd.Args = append(cmd.Args, "--cpu-num", strconv.Itoa(cpuNum)) mem, err := s.Cgroup.MemoryLimit() |