Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(hatchery/swarm): adjust http client keepAlive #3438

Merged
merged 8 commits into from
Oct 11, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions engine/hatchery/swarm/swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,27 @@ 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: 500,
MaxIdleConnsPerHost: 500,
TLSHandshakeTimeout: 30 * time.Second,
ExpectContinueTimeout: 1 * 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: 500,
MaxIdleConnsPerHost: 500,
ExpectContinueTimeout: 1 * time.Second,
}
}

Expand Down Expand Up @@ -247,7 +253,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 +279,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 +314,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
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