From cd243cfa3487a32c4af66834aba4c6c8a4adf942 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Sat, 13 Dec 2014 00:07:27 +0000 Subject: [PATCH] simplify Signed-off-by: Victor Vieux --- scheduler/strategy/binpacking.go | 12 ++++++------ scheduler/strategy/binpacking_test.go | 3 ++- 2 files changed, 8 insertions(+), 7 deletions(-) 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