Skip to content

Commit

Permalink
libpod: avoid polling container status
Browse files Browse the repository at this point in the history
use the inotify backend to be notified on the container exit instead
of polling continuosly the runtime.  Polling the runtime slowns
significantly down the podman execution time for short lived
processes:

$ time bin/podman run --rm -ti fedora true

real	0m0.324s
user	0m0.088s
sys	0m0.064s

from:

$ time podman run --rm -ti fedora true

real	0m4.199s
user	0m5.339s
sys	0m0.344s

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
  • Loading branch information
giuseppe authored and weirdwiz committed Sep 5, 2019
1 parent 151e2b9 commit fd725f8
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 543 deletions.
36 changes: 18 additions & 18 deletions libpod/container_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/opentracing/opentracing-go"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/tools/remotecommand"
)

Expand Down Expand Up @@ -524,24 +523,25 @@ func (c *Container) WaitWithInterval(waitTimeout time.Duration) (int32, error) {
if !c.valid {
return -1, define.ErrCtrRemoved
}
err := wait.PollImmediateInfinite(waitTimeout,
func() (bool, error) {
logrus.Debugf("Checking container %s status...", c.ID())
stopped, err := c.isStopped()
if err != nil {
return false, err
}
if !stopped {
return false, nil
}
return true, nil
},
)
if err != nil {
return 0, err

exitFile := c.exitFilePath()
chWait := make(chan error, 1)

defer close(chWait)

for {
// ignore errors here, it is only used to avoid waiting
// too long.
_, _ = WaitForFile(exitFile, chWait, waitTimeout)

stopped, err := c.isStopped()
if err != nil {
return -1, err
}
if stopped {
return c.state.ExitCode, nil
}
}
exitCode := c.state.ExitCode
return exitCode, nil
}

// Cleanup unmounts all mount points in container and cleans up container storage
Expand Down
6 changes: 5 additions & 1 deletion libpod/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ func WaitForFile(path string, chWait chan error, timeout time.Duration) (bool, e
defer watcher.Close()
}

timeoutChan := time.After(timeout)
var timeoutChan <-chan time.Time

if timeout != 0 {
timeoutChan = time.After(timeout)
}

for {
select {
Expand Down
19 changes: 0 additions & 19 deletions vendor/k8s.io/apimachinery/pkg/util/wait/doc.go

This file was deleted.

Loading

0 comments on commit fd725f8

Please sign in to comment.