Skip to content

Commit 728eefb

Browse files
committed
Merge branch 'debug' into 'master'
fix AllocContainerPlan bug See merge request !45
2 parents 0e084ae + 84d9b68 commit 728eefb

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.7.12c
1+
0.7.12d

utils/alloc_plan.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ func (a ByCoreNum) Len() int { return len(a) }
2020
func (a ByCoreNum) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
2121
func (a ByCoreNum) Less(i, j int) bool { return a[i].CorePer < a[j].CorePer }
2222

23+
type ByMemCap []NodeInfo
24+
25+
func (a ByMemCap) Len() int { return len(a) }
26+
func (a ByMemCap) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
27+
func (a ByMemCap) Less(i, j int) bool { return a[i].Memory < a[j].Memory }
28+
2329
func AllocContainerPlan(nodeInfo ByCoreNum, quota int, memory int64, count int) (map[string]int, error) {
2430
log.Debugf("[AllocContainerPlan]: nodeInfo: %v, quota: %d, memory: %d, count: %d", nodeInfo, quota, memory, count)
2531

@@ -40,7 +46,7 @@ func AllocContainerPlan(nodeInfo ByCoreNum, quota int, memory int64, count int)
4046
log.Debugf("[AllocContainerPlan] the %d th node has enough cpu quota.", firstNodeWithEnoughCPU)
4147

4248
// 计算是否有足够的内存满足需求
43-
nodeInfoList := []NodeInfo{}
49+
nodeInfoList := ByMemCap{}
4450
volTotal := 0
4551
volEachNode := []int{} //为了排序
4652
for i := firstNodeWithEnoughCPU; i < N; i++ {
@@ -65,6 +71,8 @@ func AllocContainerPlan(nodeInfo ByCoreNum, quota int, memory int64, count int)
6571
return result, err
6672
}
6773

74+
sort.Sort(nodeInfoList)
75+
log.Debugf("[AllocContainerPlan] sorted nodeInfo: %v, ", nodeInfoList)
6876
for i, num := range plan {
6977
key := nodeInfoList[i].Name
7078
result[key] = num

utils/utils_test.go

+11-6
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,23 @@ func TestAllocContainerPlan(t *testing.T) {
122122

123123
func TestDebugPlan(t *testing.T) {
124124
testPodInfo := ByCoreNum{}
125-
node0 := NodeInfo{"C2-docker-15", 1600000, 31442075648}
126-
node1 := NodeInfo{"C2-docker-16", 1600000, 31576293376}
127-
node2 := NodeInfo{"C2-docker-17", 1600000, 31173640192}
128-
node3 := NodeInfo{"C2-docker-14", 1600000, 27608481792}
125+
node0 := NodeInfo{"C2-docker-14", 1600000, 13732667392}
126+
node1 := NodeInfo{"C2-docker-15", 1600000, 4303872000}
127+
node2 := NodeInfo{"C2-docker-16", 1600000, 1317527552}
128+
node3 := NodeInfo{"C2-docker-17", 1600000, 8808554496}
129+
node4 := NodeInfo{"C2-docker-22", 1600000, 1527242752}
130+
node5 := NodeInfo{"C2-docker-23", 1600000, 9227984896}
131+
129132
testPodInfo = append(testPodInfo, node0)
130133
testPodInfo = append(testPodInfo, node1)
131134
testPodInfo = append(testPodInfo, node2)
132135
testPodInfo = append(testPodInfo, node3)
136+
testPodInfo = append(testPodInfo, node4)
137+
testPodInfo = append(testPodInfo, node5)
133138

134-
res, _ := AllocContainerPlan(testPodInfo, 100000, 2357198848, 1)
139+
res, _ := AllocContainerPlan(testPodInfo, 100000, 2357198848, 10)
135140
fmt.Printf("result: %v\n", res)
136-
assert.True(t, res["C2-docker-14"] == 1)
141+
assert.True(t, res["C2-docker-15"] == 1)
137142
}
138143

139144
func TestAllocAlgorithm(t *testing.T) {

0 commit comments

Comments
 (0)