Skip to content

Commit

Permalink
feature: sync parent cgroup for yarn (#68)
Browse files Browse the repository at this point in the history
Signed-off-by: suozengzeng <suozengzeng@xiaohongshu.com>
Co-authored-by: suozengzeng <suozengzeng@xiaohongshu.com>
  • Loading branch information
Suozz and suozengzeng committed Jan 26, 2024
1 parent 94bfc5a commit ea7d896
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions pkg/copilot-agent/nm/nm.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ func (n *NodeMangerOperator) syncMemoryCgroup(stop <-chan struct{}) error {
case <-n.ticker.C:
n.syncNoneProcCgroup()
n.syncAllCgroup()
_ = n.syncParentCgroup()
case <-n.nmTicker.C:
n.syncNMEndpoint()
case <-stop:
Expand Down Expand Up @@ -189,6 +190,30 @@ func (n *NodeMangerOperator) syncAllCgroup() {
}
}

func (n *NodeMangerOperator) syncParentCgroup() error {
containers, err := n.ListContainers()
if err != nil {
klog.Error(err)
return err
}
var allCpuShare int
for _, con := range containers.Containers.Items {
if con.IsFinalState() {
continue
}
allCpuShare += con.TotalVCoresNeeded * 1024
}
if allCpuShare > 0 {
cpuPath := n.GenerateCgroupFullPath(system.CgroupCPUDir)
_, err = system.CommonFileWriteIfDifferent(filepath.Join(cpuPath, system.CPUSharesName), strconv.Itoa(allCpuShare))
if err != nil {
klog.Errorf("fail to set cpu share for %s: %s", cpuPath, err.Error())
return err
}
}
return nil
}

func (n *NodeMangerOperator) removeMemoryCgroup(fileName string) {
klog.V(5).Infof("receive file delete event %s", fileName)
basename := filepath.Base(fileName)
Expand Down

0 comments on commit ea7d896

Please sign in to comment.