mirror of https://github.com/docker/docs.git
parent
b1e80ce157
commit
cd243cfa34
|
@ -14,21 +14,21 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
type BinPackingPlacementStrategy struct {
|
type BinPackingPlacementStrategy struct {
|
||||||
OvercommitRatio float64
|
ratio int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *BinPackingPlacementStrategy) Initialize(opts string) (err error) {
|
func (p *BinPackingPlacementStrategy) Initialize(opts string) error {
|
||||||
p.OvercommitRatio, err = strconv.ParseFloat(opts, 64)
|
overcommitRatio, err := strconv.ParseFloat(opts, 64)
|
||||||
|
p.ratio = int64(overcommitRatio * 100)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *BinPackingPlacementStrategy) PlaceContainer(config *dockerclient.ContainerConfig, nodes []*cluster.Node) (*cluster.Node, error) {
|
func (p *BinPackingPlacementStrategy) PlaceContainer(config *dockerclient.ContainerConfig, nodes []*cluster.Node) (*cluster.Node, error) {
|
||||||
scores := scores{}
|
scores := scores{}
|
||||||
|
|
||||||
ratio := int64(p.OvercommitRatio * 100)
|
|
||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
nodeMemory := node.Memory + (node.Memory * ratio / 100)
|
nodeMemory := node.Memory + (node.Memory * p.ratio / 100)
|
||||||
nodeCpus := node.Cpus + (node.Cpus * ratio / 100)
|
nodeCpus := node.Cpus + (node.Cpus * p.ratio / 100)
|
||||||
|
|
||||||
// Skip nodes that are smaller than the requested resources.
|
// Skip nodes that are smaller than the requested resources.
|
||||||
if nodeMemory < int64(config.Memory) || nodeCpus < config.CpuShares {
|
if nodeMemory < int64(config.Memory) || nodeCpus < config.CpuShares {
|
||||||
|
|
|
@ -114,7 +114,8 @@ func TestPlaceContainerHuge(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPlaceContainerOvercommit(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 := []*cluster.Node{createNode("node-1", 0, 1)}
|
||||||
nodes[0].Memory = 100
|
nodes[0].Memory = 100
|
||||||
|
|
Loading…
Reference in New Issue