Merge pull request #553 from noxiouz/reduce_complexity_of_pick

[Random] Pick a node for O(1), not for O(n)
This commit is contained in:
Victor Vieux 2015-04-01 15:26:10 -07:00
commit b27d405dd7
1 changed files with 3 additions and 6 deletions

View File

@ -21,12 +21,9 @@ func (p *RandomPlacementStrategy) Initialize() error {
// PlaceContainer is exported
func (p *RandomPlacementStrategy) PlaceContainer(config *dockerclient.ContainerConfig, nodes []cluster.Node) (cluster.Node, error) {
if size := len(nodes); size > 0 {
n := rand.Intn(len(nodes))
for i, node := range nodes {
if i == n {
return node, nil
}
}
index := rand.Intn(len(nodes))
return nodes[index], nil
}
return nil, errors.New("No nodes running in the cluster")
}