Skip to content

Commit 8a383bf

Browse files
author
zhangye
committed
Merge branch 'debug' into 'master'
添加了更多debug log; 去掉分配算法随机化部分 See merge request !19
2 parents 45b5df6 + 917b809 commit 8a383bf

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

cluster/calcium/create_container.go

+9
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,18 @@ func (c *calcium) createContainerWithCPUPeriod(specs types.Specs, opts *types.De
5050
go func(specs types.Specs, plan map[string]int, opts *types.DeployOptions) {
5151
wg := sync.WaitGroup{}
5252
wg.Add(len(plan))
53+
log.Debugf("alloc plan: %v", plan)
5354
for nodename, num := range plan {
55+
log.Debugf("nodename outside doCreate goroutine: %s", nodename)
56+
log.Debugf("num outside doCreate goroutine: %d", num)
57+
log.Debugf("specs outside: %v", specs)
58+
log.Debugf("opts outside: %v", opts)
5459
go func(nodename string, num int, opts *types.DeployOptions) {
5560
defer wg.Done()
61+
log.Debugf("nodename inside doCreate goroutine: %s", nodename)
62+
log.Debugf("num insid doCreate goroutine: %d", num)
63+
log.Debugf("specs inside: %v", specs)
64+
log.Debugf("opts inside: %v", opts)
5665
for _, m := range c.doCreateContainerWithCPUPeriod(nodename, num, opts.CPUQuota, specs, opts) {
5766
ch <- m
5867
}

utils/utils.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,11 @@ func allocAlgorithm(info []int, need int) map[int]int {
175175
result[j] += ave
176176
}
177177
if more > 0 {
178-
n, _ := rand.Int(rand.Reader, big.NewInt(int64(nodeToUse)))
178+
// TODO : 这里应该要有一个随机策略但是我之前的随机策略是有问题的
179+
// cmgs 提供了一个思路: 如果当前需要分配的容器数量少于最
180+
// 小机器的容量的话,我们就直接随机分
179181
more--
180-
result[j+int(n.Int64())]--
182+
result[j]--
181183
} else if more < 0 {
182184
info[j] -= ave
183185
}

utils/utils_test.go

+15
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,21 @@ func TestContinuousAddingContainer(t *testing.T) {
7474
}
7575
}
7676

77+
func TestAlgorithm(t *testing.T) {
78+
testPodInfo := ByCoreNum{}
79+
node1 := NodeInfo{"n1", 30000, 5 * 512 * 1024 * 1024}
80+
node2 := NodeInfo{"n2", 30000, 5 * 512 * 1024 * 1024}
81+
node3 := NodeInfo{"n3", 30000, 5 * 512 * 1024 * 1024}
82+
node4 := NodeInfo{"n3", 30000, 5 * 512 * 1024 * 1024}
83+
testPodInfo = append(testPodInfo, node1)
84+
testPodInfo = append(testPodInfo, node2)
85+
testPodInfo = append(testPodInfo, node3)
86+
testPodInfo = append(testPodInfo, node4)
87+
88+
res1, _ := AllocContainerPlan(testPodInfo, 10000, 512*1024*1024, 1)
89+
fmt.Println(res1)
90+
}
91+
7792
func TestAllocContainerPlan(t *testing.T) {
7893
testPodInfo := ByCoreNum{}
7994
node1 := NodeInfo{"n1", 30000, 512 * 1024 * 1024}

0 commit comments

Comments
 (0)