Skip to content

Commit

Permalink
Merge branch 'dev' into 'master'
Browse files Browse the repository at this point in the history
randomized AllocContainerPlan



See merge request !14
  • Loading branch information
tonic committed Sep 22, 2016
2 parents 176b7cf + 363eef8 commit 6a1048c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
16 changes: 10 additions & 6 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,19 @@ func AllocContainerPlan(nodeInfo ByCoreNum, quota int, count int) (map[string]in
for i := flag; i < N; i++ {
result[nodeInfo[i].Name] = ave
}
resLen := int64(len(result))
if remain > 0 {
r:
for {
for node, _ := range result {
result[node] += 1
remain--
if remain <= 0 {
break r
}
// 考虑一种情况:不断申请一个 quota 相同的容器
// 按原来的算法,这个容器会堆积在同一台机上面
// 加入随机化的选择可以避免这种情况
step, _ := rand.Int(rand.Reader, big.NewInt(resLen))
node := nodeInfo[flag+int(step.Int64())].Name
result[node] += 1
remain--
if remain <= 0 {
break r
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,19 @@ func TestGetGitRepoName(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, r1, "core")
}

func TestContinuousAddingContainer(t *testing.T) {
testPodInfo := ByCoreNum{}
node1 := NodeInfo{"n1", 20000}
node2 := NodeInfo{"n2", 30000}
// node3 := NodeInfo{"n3", 10000}
testPodInfo = append(testPodInfo, node1)
testPodInfo = append(testPodInfo, node2)
// testPodInfo = append(testPodInfo, node3)

for i := 0; i < 10; i++ {
res, err := AllocContainerPlan(testPodInfo, 10000, 1)
fmt.Println(res)
assert.NoError(t, err)
}
}

0 comments on commit 6a1048c

Please sign in to comment.