diff --git a/scheduler/strategy/binpacking.go b/scheduler/strategy/binpacking.go index cf3520a77d..ccd38ceb2c 100644 --- a/scheduler/strategy/binpacking.go +++ b/scheduler/strategy/binpacking.go @@ -14,21 +14,21 @@ var ( ) type BinPackingPlacementStrategy struct { - OvercommitRatio float64 + ratio int64 } -func (p *BinPackingPlacementStrategy) Initialize(opts string) (err error) { - p.OvercommitRatio, err = strconv.ParseFloat(opts, 64) +func (p *BinPackingPlacementStrategy) Initialize(opts string) error { + overcommitRatio, err := strconv.ParseFloat(opts, 64) + p.ratio = int64(overcommitRatio * 100) return err } func (p *BinPackingPlacementStrategy) PlaceContainer(config *dockerclient.ContainerConfig, nodes []*cluster.Node) (*cluster.Node, error) { scores := scores{} - ratio := int64(p.OvercommitRatio * 100) for _, node := range nodes { - nodeMemory := node.Memory + (node.Memory * ratio / 100) - nodeCpus := node.Cpus + (node.Cpus * ratio / 100) + nodeMemory := node.Memory + (node.Memory * p.ratio / 100) + nodeCpus := node.Cpus + (node.Cpus * p.ratio / 100) // Skip nodes that are smaller than the requested resources. if nodeMemory < int64(config.Memory) || nodeCpus < config.CpuShares { diff --git a/scheduler/strategy/binpacking_test.go b/scheduler/strategy/binpacking_test.go index 79579654a8..d4e2aba8a2 100644 --- a/scheduler/strategy/binpacking_test.go +++ b/scheduler/strategy/binpacking_test.go @@ -114,7 +114,8 @@ func TestPlaceContainerHuge(t *testing.T) { } func TestPlaceContainerOvercommit(t *testing.T) { - s := &BinPackingPlacementStrategy{OvercommitRatio: 0.05} + s, err := New("binpacking:0.05") + assert.NoError(t, err) nodes := []*cluster.Node{createNode("node-1", 0, 1)} nodes[0].Memory = 100