mirror of https://github.com/docker/docs.git
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:
commit
b27d405dd7
|
|
@ -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")
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue