Skip to content

Commit

Permalink
discovery: getOrch timeout per orchestrators instead of for all
Browse files Browse the repository at this point in the history
  • Loading branch information
kyriediculous committed Jun 11, 2021
1 parent c3e0b7b commit b8c39af
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import (
"github.com/golang/glog"
)

var getOrchestratorsTimeoutLoop = 1 * time.Second
var getOrchestratorsTimeoutLoop = 500 * time.Millisecond
var getOrchestratorCutoffTime = 4 * time.Second

var serverGetOrchInfo = server.GetOrchestratorInfo

Expand Down Expand Up @@ -49,7 +50,6 @@ func (o *orchestratorPool) GetURLs() []*url.URL {
func (o *orchestratorPool) GetOrchestrators(numOrchestrators int, suspender common.Suspender, caps common.CapabilityComparator) ([]*net.OrchestratorInfo, error) {
numAvailableOrchs := len(o.uris)
numOrchestrators = int(math.Min(float64(numAvailableOrchs), float64(numOrchestrators)))
ctx, cancel := context.WithTimeout(context.Background(), getOrchestratorsTimeoutLoop)

infoCh := make(chan *net.OrchestratorInfo, numAvailableOrchs)
errCh := make(chan error, numAvailableOrchs)
Expand Down Expand Up @@ -81,6 +81,8 @@ func (o *orchestratorPool) GetOrchestrators(numOrchestrators int, suspender comm
return caps.CompatibleWith(info.Capabilities)
}
getOrchInfo := func(uri *url.URL) {
ctx, cancel := context.WithTimeout(context.Background(), getOrchestratorsTimeoutLoop)
defer cancel()
info, err := serverGetOrchInfo(ctx, o.bcast, uri)
if err == nil && isCompatible(info) {
infoCh <- info
Expand All @@ -101,6 +103,8 @@ func (o *orchestratorPool) GetOrchestrators(numOrchestrators int, suspender comm
uris[i] = o.uris[j]
}

ctx, cancel := context.WithTimeout(context.Background(), getOrchestratorCutoffTime)

for _, uri := range uris {
go getOrchInfo(uri)
}
Expand Down

0 comments on commit b8c39af

Please sign in to comment.