Skip to content

Commit 3da1102

Browse files
author
suozengzeng
committed
feature: sync parent cgroup for yarn
1 parent 94bfc5a commit 3da1102

File tree

1 file changed

+25
-0
lines changed
  • pkg/copilot-agent/nm

1 file changed

+25
-0
lines changed

pkg/copilot-agent/nm/nm.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ func (n *NodeMangerOperator) syncMemoryCgroup(stop <-chan struct{}) error {
110110
case <-n.ticker.C:
111111
n.syncNoneProcCgroup()
112112
n.syncAllCgroup()
113+
_ = n.syncParentCgroup()
113114
case <-n.nmTicker.C:
114115
n.syncNMEndpoint()
115116
case <-stop:
@@ -189,6 +190,30 @@ func (n *NodeMangerOperator) syncAllCgroup() {
189190
}
190191
}
191192

193+
func (n *NodeMangerOperator) syncParentCgroup() error {
194+
containers, err := n.ListContainers()
195+
if err != nil {
196+
klog.Error(err)
197+
return err
198+
}
199+
var allCpuShare int
200+
for _, con := range containers.Containers.Items {
201+
if con.IsFinalState() {
202+
continue
203+
}
204+
allCpuShare += con.TotalVCoresNeeded * 1024
205+
}
206+
if allCpuShare > 0 {
207+
cpuPath := n.GenerateCgroupFullPath(system.CgroupCPUDir)
208+
_, err = system.CommonFileWriteIfDifferent(filepath.Join(cpuPath, system.CPUSharesName), strconv.Itoa(allCpuShare))
209+
if err != nil {
210+
klog.Errorf("fail to set cpu share for %s: %s", cpuPath, err.Error())
211+
return err
212+
}
213+
}
214+
return nil
215+
}
216+
192217
func (n *NodeMangerOperator) removeMemoryCgroup(fileName string) {
193218
klog.V(5).Infof("receive file delete event %s", fileName)
194219
basename := filepath.Base(fileName)

0 commit comments

Comments
 (0)