mirror of https://github.com/docker/docs.git
[Random] Pick a node for O(1), not for O(n)
Signed-off-by: Anton Tiurin <noxiouz@yandex.ru>
This commit is contained in:
parent
1f2bd67555
commit
f760b25e12
|
@ -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