From 8fffc52956d4fafdeb9dab3e5ce35ec56b5e352e Mon Sep 17 00:00:00 2001 From: CMGS Date: Tue, 24 Oct 2017 16:27:35 +0800 Subject: [PATCH] allow cpu prior oversell --- scheduler/complex/cpu.go | 8 +++----- scheduler/complex/potassium_test.go | 19 +++++++++++++++++-- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/scheduler/complex/cpu.go b/scheduler/complex/cpu.go index b0060cb7b..41978795e 100644 --- a/scheduler/complex/cpu.go +++ b/scheduler/complex/cpu.go @@ -38,8 +38,8 @@ func newHost(cpuInfo types.CPUMap, share int64) *host { fragment: types.CPUMap{}, } for no, pieces := range cpuInfo { - if pieces == share { - result.full[no] = pieces + if pieces >= share { + result.full[no] = share } else { result.fragment[no] = pieces } @@ -175,9 +175,7 @@ func (h *host) getFullResult(full int64) types.CPUMap { return result } -func cpuPriorPlan(cpu float64, nodesInfo []types.NodeInfo, need int, maxShareCore, coreShare int64) ( - int, []types.NodeInfo, map[string][]types.CPUMap) { - +func cpuPriorPlan(cpu float64, nodesInfo []types.NodeInfo, need int, maxShareCore, coreShare int64) (int, []types.NodeInfo, map[string][]types.CPUMap) { var nodeContainer = map[string][]types.CPUMap{} var host *host var plan []types.CPUMap diff --git a/scheduler/complex/potassium_test.go b/scheduler/complex/potassium_test.go index cedf40188..11551811d 100644 --- a/scheduler/complex/potassium_test.go +++ b/scheduler/complex/potassium_test.go @@ -250,9 +250,8 @@ func TestComplexNodes(t *testing.T) { t.Fatalf("Create Potassim error: %v", merr) } - nodes := getNodesInfo() - k, _ = New(coreCfg) // test1 + nodes := getNodesInfo() res1, changed1, err := k.SelectCPUNodes(nodes, 1.7, 7) if err != nil { t.Fatalf("sth wrong") @@ -297,6 +296,22 @@ func TestComplexNodes(t *testing.T) { assert.Equal(t, err.Error(), "quota must positive") } +func TestCPUOverSell(t *testing.T) { + coreCfg := newConfig() + coreCfg.Scheduler.ShareBase = 5 + k, err := New(coreCfg) + if err != nil { + t.Fatalf("Create Potassim error: %v", err) + } + + //test1 + nodes := getNodesInfo() + _, _, err = k.SelectCPUNodes(nodes, 1.7, 3) + assert.NoError(t, err) + + //TODO 增加其他测试吧,这里应该是没问题的 +} + func getEvenPlanNodes() []types.NodeInfo { return []types.NodeInfo{ types.NodeInfo{