Skip to content

Commit ce496b6

Browse files
author
zc
authored
check cpu suffience when realloc (#236)
1 parent a9d896f commit ce496b6

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

cluster/calcium/realloc.go

+4
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ func (c *Calcium) doReallocContainer(ctx context.Context, ch chan *types.Realloc
138138
}
139139
// 得到最终方案
140140
cpusets = nodeCPUPlans[node.Name][:containerWithCPUBind]
141+
} else if newCPU != 0 { // nolint
142+
if cap := float64(node.InitCPU.Total()) / float64(c.config.Scheduler.ShareBase) / newCPU; int(cap) < len(containers) { // nolint
143+
return types.NewDetailedErr(types.ErrInsufficientCPU, node.Name)
144+
}
141145
}
142146

143147
newResource := &enginetypes.VirtualizationResource{

cluster/calcium/realloc_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func TestRealloc(t *testing.T) {
3434
ctx := context.Background()
3535
store := &storemocks.Store{}
3636
c.store = store
37+
c.config.Scheduler.ShareBase = 100
3738

3839
lock := &lockmocks.DistributedLock{}
3940
lock.On("Lock", mock.Anything).Return(nil)
@@ -50,6 +51,7 @@ func TestRealloc(t *testing.T) {
5051
Name: "node1",
5152
MemCap: int64(units.GiB),
5253
CPU: types.CPUMap{"0": 10, "1": 70, "2": 10, "3": 100},
54+
InitCPU: types.CPUMap{"0": 100, "1": 100, "2": 100, "3": 100},
5355
Engine: engine,
5456
Endpoint: "http://1.1.1.1:1",
5557
NUMA: types.NUMA{"2": "0"},
@@ -210,6 +212,7 @@ func TestRealloc(t *testing.T) {
210212
Name: "node2",
211213
MemCap: int64(units.GiB),
212214
CPU: types.CPUMap{"0": 10, "1": 70, "2": 10, "3": 100},
215+
InitCPU: types.CPUMap{"0": 100, "1": 100, "2": 100, "3": 100},
213216
Engine: engine,
214217
Endpoint: "http://1.1.1.1:1",
215218
NUMA: types.NUMA{"2": "0"},
@@ -406,6 +409,7 @@ func TestReallocVolume(t *testing.T) {
406409

407410
func TestReallocBindCpu(t *testing.T) {
408411
c := NewTestCluster()
412+
c.config.Scheduler.ShareBase = 100
409413
ctx := context.Background()
410414
store := &storemocks.Store{}
411415
c.store = store
@@ -445,6 +449,7 @@ func TestReallocBindCpu(t *testing.T) {
445449
Name: "node3",
446450
MemCap: int64(units.GiB),
447451
CPU: types.CPUMap{"0": 10, "1": 70, "2": 10, "3": 100},
452+
InitCPU: types.CPUMap{"0": 100, "1": 100, "2": 100, "3": 100},
448453
CPUUsed: 2.1,
449454
Engine: engine,
450455
Endpoint: "http://1.1.1.1:1",

scheduler/complex/potassium.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ func (m *Potassium) SelectMemoryNodes(nodesInfo []types.NodeInfo, quota float64,
8080

8181
// 筛选出能满足 CPU 需求的
8282
sort.Slice(nodesInfo, func(i, j int) bool { return len(nodesInfo[i].CPUMap) < len(nodesInfo[j].CPUMap) })
83-
p := sort.Search(nodesInfoLength, func(i int) bool { return float64(len(nodesInfo[i].CPUMap)) >= quota })
83+
p := sort.Search(nodesInfoLength, func(i int) bool {
84+
return float64(len(nodesInfo[i].CPUMap)) >= quota
85+
})
8486
// p 最大也就是 nodesInfoLength - 1
8587
if p == nodesInfoLength {
8688
return nil, 0, types.ErrInsufficientCPU

0 commit comments

Comments
 (0)