Skip to content

Commit 4bc2110

Browse files
committed
[launcher] Set CPU quota period to 100ms and fix CPU count usage
Signed-off-by: Oleksandr Grytsov <oleksandr_grytsov@epam.com>
1 parent cf5c04a commit 4bc2110

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

launcher/launcher_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"os/exec"
2828
"path/filepath"
2929
"reflect"
30+
"runtime"
3031
"strconv"
3132
"strings"
3233
"sync"
@@ -821,7 +822,8 @@ func TestRuntimeSpec(t *testing.T) {
821822
t.Errorf("Wrong CPU period value: %d", *runtimeSpec.Linux.Resources.CPU.Period)
822823
}
823824

824-
if *runtimeSpec.Linux.Resources.CPU.Quota != int64(*serviceConfig.Quotas.CPULimit) {
825+
if *runtimeSpec.Linux.Resources.CPU.Quota != int64(*serviceConfig.Quotas.CPULimit*
826+
(*runtimeSpec.Linux.Resources.CPU.Period)*uint64(runtime.NumCPU())/nodeInfoProvider.nodeInfo.MaxDMIPs) {
825827
t.Errorf("Wrong CPU quota value: %d", *runtimeSpec.Linux.Resources.CPU.Quota)
826828
}
827829

launcher/spec.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"os/user"
2727
"path"
2828
"path/filepath"
29+
"runtime"
2930
"strconv"
3031
"strings"
3132

@@ -45,6 +46,8 @@ import (
4546
* Consts
4647
**********************************************************************************************************************/
4748

49+
const defaultCPUPeriod uint64 = 100000
50+
4851
const cgroupsPath = "/system.slice/system-aos\\x2dservice.slice/"
4952

5053
const (
@@ -112,9 +115,10 @@ func (spec *runtimeSpec) setCPULimit(cpuLimit uint64) {
112115
spec.ociSpec.Linux.Resources.CPU = &runtimespec.LinuxCPU{}
113116
}
114117

115-
cpuQuota := int64(cpuLimit)
118+
cpuPeriod := defaultCPUPeriod
119+
cpuQuota := int64(cpuLimit * defaultCPUPeriod * uint64(runtime.NumCPU()) / spec.nodeInfo.MaxDMIPs)
116120

117-
spec.ociSpec.Linux.Resources.CPU.Period = &spec.nodeInfo.MaxDMIPs
121+
spec.ociSpec.Linux.Resources.CPU.Period = &cpuPeriod
118122
spec.ociSpec.Linux.Resources.CPU.Quota = &cpuQuota
119123
}
120124

0 commit comments

Comments
 (0)