mirror of https://github.com/docker/docs.git
Move overcommit outside of binpacking and use 105 instead of 0.05
Signed-off-by: Victor Vieux <vieux@docker.com>
This commit is contained in:
parent
2e156fb692
commit
d8b609c161
7
flags.go
7
flags.go
|
@ -50,10 +50,15 @@ var (
|
|||
Name: "tlsverify",
|
||||
Usage: "use TLS and verify the remote",
|
||||
}
|
||||
flOverCommit = cli.IntFlag{
|
||||
Name: "overcommit, oc",
|
||||
Usage: "overcommit to apply on resources",
|
||||
Value: 105,
|
||||
}
|
||||
flStrategy = cli.StringFlag{
|
||||
Name: "strategy",
|
||||
Usage: "placement strategy to use [binpacking, random]",
|
||||
Value: "binpacking:0.05",
|
||||
Value: "binpacking",
|
||||
}
|
||||
flFilter = cli.StringSliceFlag{
|
||||
Name: "filter, f",
|
||||
|
|
2
main.go
2
main.go
|
@ -87,7 +87,7 @@ func main() {
|
|||
Flags: []cli.Flag{
|
||||
flDiscovery,
|
||||
flStrategy, flFilter,
|
||||
flHosts, flHeartBeat,
|
||||
flHosts, flHeartBeat, flOverCommit,
|
||||
flTls, flTlsCaCert, flTlsCert, flTlsKey, flTlsVerify,
|
||||
flEnableCors},
|
||||
Action: manage,
|
||||
|
|
|
@ -78,7 +78,7 @@ func manage(c *cli.Context) {
|
|||
log.Fatal("--discovery required to manage a cluster")
|
||||
}
|
||||
|
||||
s, err := strategy.New(c.String("strategy"))
|
||||
s, err := strategy.New(c.String("strategy"), int64(c.Int("overcommit")))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package strategy
|
|||
import (
|
||||
"errors"
|
||||
"sort"
|
||||
"strconv"
|
||||
|
||||
"github.com/docker/swarm/cluster"
|
||||
"github.com/samalba/dockerclient"
|
||||
|
@ -14,21 +13,20 @@ var (
|
|||
)
|
||||
|
||||
type BinPackingPlacementStrategy struct {
|
||||
ratio int64
|
||||
overcommitRatio int64
|
||||
}
|
||||
|
||||
func (p *BinPackingPlacementStrategy) Initialize(opts string) error {
|
||||
overcommitRatio, err := strconv.ParseFloat(opts, 64)
|
||||
p.ratio = int64(overcommitRatio * 100)
|
||||
return err
|
||||
func (p *BinPackingPlacementStrategy) Initialize(overcommitRatio int64) error {
|
||||
p.overcommitRatio = overcommitRatio - 100
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *BinPackingPlacementStrategy) PlaceContainer(config *dockerclient.ContainerConfig, nodes []*cluster.Node) (*cluster.Node, error) {
|
||||
scores := scores{}
|
||||
|
||||
for _, node := range nodes {
|
||||
nodeMemory := node.Memory + (node.Memory * p.ratio / 100)
|
||||
nodeCpus := node.Cpus + (node.Cpus * p.ratio / 100)
|
||||
nodeMemory := node.Memory + (node.Memory * p.overcommitRatio / 100)
|
||||
nodeCpus := node.Cpus + (node.Cpus * p.overcommitRatio / 100)
|
||||
|
||||
// Skip nodes that are smaller than the requested resources.
|
||||
if nodeMemory < int64(config.Memory) || nodeCpus < config.CpuShares {
|
||||
|
|
|
@ -114,7 +114,7 @@ func TestPlaceContainerHuge(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestPlaceContainerOvercommit(t *testing.T) {
|
||||
s, err := New("binpacking:0.05")
|
||||
s, err := New("binpacking", 105)
|
||||
assert.NoError(t, err)
|
||||
|
||||
nodes := []*cluster.Node{createNode("node-1", 0, 1)}
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
type RandomPlacementStrategy struct {
|
||||
}
|
||||
|
||||
func (p *RandomPlacementStrategy) Initialize(_ string) error {
|
||||
func (p *RandomPlacementStrategy) Initialize(_ int64) error {
|
||||
rand.Seed(time.Now().UTC().UnixNano())
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package strategy
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"github.com/docker/swarm/cluster"
|
||||
|
@ -10,7 +9,7 @@ import (
|
|||
)
|
||||
|
||||
type PlacementStrategy interface {
|
||||
Initialize(string) error
|
||||
Initialize(overcommitRatio int64) error
|
||||
// Given a container configuration and a set of nodes, select the target
|
||||
// node where the container should be scheduled.
|
||||
PlaceContainer(config *dockerclient.ContainerConfig, nodes []*cluster.Node) (*cluster.Node, error)
|
||||
|
@ -28,19 +27,10 @@ func init() {
|
|||
}
|
||||
}
|
||||
|
||||
func New(nameAndOpts string) (PlacementStrategy, error) {
|
||||
var (
|
||||
parts = strings.SplitN(nameAndOpts, ":", 2)
|
||||
name = parts[0]
|
||||
opts string
|
||||
)
|
||||
if len(parts) == 2 {
|
||||
opts = parts[1]
|
||||
}
|
||||
|
||||
func New(name string, overcommitRatio int64) (PlacementStrategy, error) {
|
||||
if strategy, exists := strategies[name]; exists {
|
||||
log.Debugf("Initializing %q strategy with %q", name, opts)
|
||||
err := strategy.Initialize(opts)
|
||||
log.Debugf("Initializing %q strategy", name)
|
||||
err := strategy.Initialize(overcommitRatio)
|
||||
return strategy, err
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue