From 82ca2002e0852f07fb1e18ac516bbbce4350b873 Mon Sep 17 00:00:00 2001 From: Xinfeng Liu Date: Mon, 6 Jan 2020 10:04:48 +0800 Subject: [PATCH 1/2] Make addProcess() parallel Following Crosby's patch, this commit makes launching health-check processes faster when many health-checks occur simultaneously. It helps avoiding health-check timeouts that Paypal ran into. (FIELD-2190) In addition, this commit adds a lock to protect accessing to 'processes' map of the container. Signed-off-by: Xinfeng Liu --- runtime/container.go | 10 +++++++++ supervisor/add_process.go | 47 ++++++++++++++++++++++----------------- 2 files changed, 36 insertions(+), 21 deletions(-) diff --git a/runtime/container.go b/runtime/container.go index a9677c4ad6e3..a3cdb887ccda 100644 --- a/runtime/container.go +++ b/runtime/container.go @@ -9,6 +9,7 @@ import ( "os/exec" "path/filepath" "strings" + "sync" "syscall" "time" @@ -228,6 +229,7 @@ type container struct { runtime string runtimeArgs []string shim string + pmu sync.Mutex processes map[string]*process labels []string oomFds []int @@ -278,19 +280,25 @@ func (c *container) Delete() error { func (c *container) Processes() ([]Process, error) { out := []Process{} + c.pmu.Lock() for _, p := range c.processes { out = append(out, p) } + c.pmu.Unlock() return out, nil } func (c *container) RemoveProcess(pid string) error { + c.pmu.Lock() delete(c.processes, pid) + c.pmu.Unlock() return os.RemoveAll(filepath.Join(c.root, c.id, pid)) } func (c *container) State() State { + c.pmu.Lock() proc := c.processes[InitProcessID] + c.pmu.Unlock() if proc == nil { return Stopped } @@ -532,7 +540,9 @@ func (c *container) createCmd(ctx context.Context, pid string, cmd *exec.Cmd, p ch <- err return } + c.pmu.Lock() c.processes[pid] = p + c.pmu.Unlock() ch <- nil }() select { diff --git a/supervisor/add_process.go b/supervisor/add_process.go index b5fc40cb8795..9255d3a828a2 100644 --- a/supervisor/add_process.go +++ b/supervisor/add_process.go @@ -27,25 +27,30 @@ func (s *Supervisor) addProcess(t *AddProcessTask) error { if !ok { return ErrContainerNotFound } - process, err := ci.container.Exec(t.Ctx(), t.PID, *t.ProcessSpec, runtime.NewStdio(t.Stdin, t.Stdout, t.Stderr)) - if err != nil { - return err - } - s.newExecSyncChannel(t.ID, t.PID) - if err := s.monitorProcess(process); err != nil { - s.deleteExecSyncChannel(t.ID, t.PID) - // Kill process - process.Signal(os.Kill) - ci.container.RemoveProcess(t.PID) - return err - } - ExecProcessTimer.UpdateSince(start) - t.StartResponse <- StartResponse{ExecPid: process.SystemPid()} - s.notifySubscribers(Event{ - Timestamp: time.Now(), - Type: StateStartProcess, - PID: t.PID, - ID: t.ID, - }) - return nil + go func() { + process, err := ci.container.Exec(t.Ctx(), t.PID, *t.ProcessSpec, runtime.NewStdio(t.Stdin, t.Stdout, t.Stderr)) + if err != nil { + t.errCh <- err + return + } + s.newExecSyncChannel(t.ID, t.PID) + if err := s.monitorProcess(process); err != nil { + s.deleteExecSyncChannel(t.ID, t.PID) + // Kill process + process.Signal(os.Kill) + ci.container.RemoveProcess(t.PID) + t.errCh <- err + return + } + ExecProcessTimer.UpdateSince(start) + t.errCh <- nil + t.StartResponse <- StartResponse{ExecPid: process.SystemPid()} + s.notifySubscribers(Event{ + Timestamp: time.Now(), + Type: StateStartProcess, + PID: t.PID, + ID: t.ID, + }) + }() + return errDeferredResponse } From 1218117bf3a92d2b5672c364731f55f5fe7a26a8 Mon Sep 17 00:00:00 2001 From: Xinfeng Liu Date: Mon, 6 Jan 2020 11:12:00 +0800 Subject: [PATCH 2/2] Update travis to use go 1.10.x To fix "go get -u github.com/golang/lint/golint" error. https://github.com/golang/lint/issues/421 Signed-off-by: Xinfeng Liu --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 690b670f65cc..23377bf6aee4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,8 +4,7 @@ sudo: required language: go go: - - 1.8.x - - tip + - 1.10.x go_import_path: github.com/containerd/containerd