Skip to content

Commit

Permalink
fix(hatchery/swarm): adjust http client keepAlive (#3438)
Browse files Browse the repository at this point in the history
Signed-off-by: Yvonnick Esnault <yvonnick.esnault@corp.ovh.com>
  • Loading branch information
yesnault authored and bnjjj committed Oct 11, 2018
1 parent 64909bd commit cc8b7fb
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 16 deletions.
39 changes: 24 additions & 15 deletions engine/hatchery/swarm/swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,30 @@ func (h *HatcherySwarm) Init() error {

if tlsc != nil {
httpClient.Transport = &http.Transport{
Dial: (&net.Dialer{
Timeout: 30 * time.Second,
}).Dial,
MaxIdleConns: 500,
MaxIdleConnsPerHost: 500,
TLSHandshakeTimeout: 30 * time.Second,
TLSClientConfig: tlsc,
DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 0 * time.Second,
DualStack: true,
}).DialContext,
MaxIdleConns: 100,
IdleConnTimeout: 20 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
ResponseHeaderTimeout: 30 * time.Second,
TLSClientConfig: tlsc,
}
} else {
httpClient.Transport = &http.Transport{
Dial: (&net.Dialer{
Timeout: 30 * time.Second,
}).Dial,
MaxIdleConns: 500,
MaxIdleConnsPerHost: 500,
DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 0 * time.Second,
DualStack: true,
}).DialContext,
MaxIdleConns: 100,
IdleConnTimeout: 20 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
ResponseHeaderTimeout: 30 * time.Second,
}
}

Expand Down Expand Up @@ -247,7 +256,7 @@ func (h *HatcherySwarm) SpawnWorker(ctx context.Context, spawnArgs hatchery.Spaw
network = name + "-net"
networkAlias = "worker"
if err := h.createNetwork(ctx, dockerClient, network); err != nil {
log.Warning("hatchery> swarm> SpawnWorker> Unable to create network %s for jobID %d : %v", network, spawnArgs.JobID, err)
log.Warning("hatchery> swarm> SpawnWorker> Unable to create network %s on %s for jobID %d : %v", network, dockerClient.name, spawnArgs.JobID, err)
next()
return "", err
}
Expand All @@ -273,7 +282,7 @@ func (h *HatcherySwarm) SpawnWorker(ctx context.Context, spawnArgs hatchery.Spaw
m := strings.Replace(e, "CDS_SERVICE_MEMORY=", "", -1)
i, err := strconv.Atoi(m)
if err != nil {
log.Warning("hatchery> swarm> SpawnWorker> Unable to parse service option %s : %s", e, err)
log.Warning("hatchery> swarm> SpawnWorker> Unable to parse service option %s : %v", e, err)
continue
}
serviceMemory = int64(i)
Expand Down Expand Up @@ -308,7 +317,7 @@ func (h *HatcherySwarm) SpawnWorker(ctx context.Context, spawnArgs hatchery.Spaw
}

if err := h.createAndStartContainer(ctx, dockerClient, args, spawnArgs); err != nil {
log.Warning("hatchery> swarm> SpawnWorker> Unable to start required container: %s", err)
log.Warning("hatchery> swarm> SpawnWorker> Unable to start required container on %s: %s", dockerClient.name, err)
return "", err
}
services = append(services, serviceName)
Expand Down
1 change: 1 addition & 0 deletions sdk/cdsclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func NewHTTPClient(timeout time.Duration, insecureSkipVerifyTLS bool) *http.Clie
IdleConnTimeout: 30 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
ResponseHeaderTimeout: 30 * time.Second,
TLSClientConfig: &tls.Config{InsecureSkipVerify: insecureSkipVerifyTLS},
},
}
Expand Down
4 changes: 3 additions & 1 deletion sdk/cdsclient/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,9 @@ func (c *client) Stream(ctx context.Context, method string, path string, body io
}
continue
}

if resp != nil && resp.Body != nil {
resp.Body.Close()
}
if errDo != nil {
return nil, nil, 0, errDo
}
Expand Down
6 changes: 6 additions & 0 deletions sdk/hatchery/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ func workerRegister(h Interface, startWorkerChan chan<- workerStarterRequest) er
if models[k].Type != h.ModelType() {
continue
}
if h.NeedRegistration(&models[k]) || models[k].CheckRegistration {
log.Debug("hatchery> workerRegister> need register")
} else {
continue
}

maxRegistration := int64(math.Floor(float64(h.Configuration().Provision.MaxWorker) / 4))
if atomic.LoadInt64(&nbRegisteringWorkerModels) > maxRegistration {
log.Debug("hatchery> workerRegister> max registering worker reached")
Expand Down

0 comments on commit cc8b7fb

Please sign in to comment.