1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Fix high cpu usage caused by docker stats.

Signed-off-by: Tianyi Wang <capkurmagati@gmail.com>
(cherry picked from commit 54e8beec9b)
Signed-off-by: Tibor Vass <tibor@docker.com>
This commit is contained in:
Tianyi Wang 2016-06-24 01:49:45 +09:00 committed by Tibor Vass
parent 82219c7727
commit 14038215d3
2 changed files with 14 additions and 0 deletions

View file

@ -192,13 +192,23 @@ func runStats(dockerCli *client.DockerCli, opts *statsOptions) error {
for range time.Tick(500 * time.Millisecond) {
printHeader()
toRemove := []string{}
cStats.mu.Lock()
for _, s := range cStats.cs {
if err := s.Display(w); err != nil && !opts.noStream {
logrus.Debugf("stats: got error for %s: %v", s.Name, err)
if err == io.EOF {
toRemove = append(toRemove, s.Name)
}
}
}
cStats.mu.Unlock()
for _, name := range toRemove {
cStats.remove(name)
}
if len(cStats.cs) == 0 && !showAll {
return nil
}
w.Flush()
if opts.noStream {
break

View file

@ -97,6 +97,10 @@ func (s *containerStats) Collect(ctx context.Context, cli client.APIClient, stre
if err := dec.Decode(&v); err != nil {
dec = json.NewDecoder(io.MultiReader(dec.Buffered(), responseBody))
u <- err
if err == io.EOF {
break
}
time.Sleep(100 * time.Millisecond)
continue
}