Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check cpu sufficiency when realloc #236

Merged
merged 1 commit into from
Jul 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cluster/calcium/realloc.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ func (c *Calcium) doReallocContainer(ctx context.Context, ch chan *types.Realloc
}
// 得到最终方案
cpusets = nodeCPUPlans[node.Name][:containerWithCPUBind]
} else if newCPU != 0 { // nolint
if cap := float64(node.InitCPU.Total()) / float64(c.config.Scheduler.ShareBase) / newCPU; int(cap) < len(containers) { // nolint
return types.NewDetailedErr(types.ErrInsufficientCPU, node.Name)
}
}

newResource := &enginetypes.VirtualizationResource{
Expand Down
5 changes: 5 additions & 0 deletions cluster/calcium/realloc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func TestRealloc(t *testing.T) {
ctx := context.Background()
store := &storemocks.Store{}
c.store = store
c.config.Scheduler.ShareBase = 100

lock := &lockmocks.DistributedLock{}
lock.On("Lock", mock.Anything).Return(nil)
Expand All @@ -50,6 +51,7 @@ func TestRealloc(t *testing.T) {
Name: "node1",
MemCap: int64(units.GiB),
CPU: types.CPUMap{"0": 10, "1": 70, "2": 10, "3": 100},
InitCPU: types.CPUMap{"0": 100, "1": 100, "2": 100, "3": 100},
Engine: engine,
Endpoint: "http://1.1.1.1:1",
NUMA: types.NUMA{"2": "0"},
Expand Down Expand Up @@ -210,6 +212,7 @@ func TestRealloc(t *testing.T) {
Name: "node2",
MemCap: int64(units.GiB),
CPU: types.CPUMap{"0": 10, "1": 70, "2": 10, "3": 100},
InitCPU: types.CPUMap{"0": 100, "1": 100, "2": 100, "3": 100},
Engine: engine,
Endpoint: "http://1.1.1.1:1",
NUMA: types.NUMA{"2": "0"},
Expand Down Expand Up @@ -406,6 +409,7 @@ func TestReallocVolume(t *testing.T) {

func TestReallocBindCpu(t *testing.T) {
c := NewTestCluster()
c.config.Scheduler.ShareBase = 100
ctx := context.Background()
store := &storemocks.Store{}
c.store = store
Expand Down Expand Up @@ -445,6 +449,7 @@ func TestReallocBindCpu(t *testing.T) {
Name: "node3",
MemCap: int64(units.GiB),
CPU: types.CPUMap{"0": 10, "1": 70, "2": 10, "3": 100},
InitCPU: types.CPUMap{"0": 100, "1": 100, "2": 100, "3": 100},
CPUUsed: 2.1,
Engine: engine,
Endpoint: "http://1.1.1.1:1",
Expand Down
4 changes: 3 additions & 1 deletion scheduler/complex/potassium.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ func (m *Potassium) SelectMemoryNodes(nodesInfo []types.NodeInfo, quota float64,

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