diff options
author | Alexander Larsson <alexl@redhat.com> | 2022-10-06 17:49:00 +0200 |
---|---|---|
committer | Alexander Larsson <alexl@redhat.com> | 2022-10-07 10:13:26 +0200 |
commit | 5b71070e421b7491bfc9046dea1ae94888cbb6d4 (patch) | |
tree | a84792f1c02b05eeb28512c9cedf4881c90a00b4 | |
parent | 13a1c55d3f0d0cb9a34e865844278e935337cd1b (diff) | |
download | podman-5b71070e421b7491bfc9046dea1ae94888cbb6d4.tar.gz podman-5b71070e421b7491bfc9046dea1ae94888cbb6d4.tar.bz2 podman-5b71070e421b7491bfc9046dea1ae94888cbb6d4.zip |
libpod: Remove 100msec delay during shutdown
When shutting down the image engine we always wait for the image
even goroutine to finish writing any outstanding events. However,
the loop for that always waits 100msec every iteration. This means
that (depending on the phase) shutdown is always delayed up to 100msec.
This is delaying "podman run" extra much because podman is run twice
(once for the run and once as cleanup via a conmon callback).
Changing the image loop to exit immediately when a libimageEventsShutdown
(but first checking for any outstanding events to write) improves podman
run times by about 100msec on average.
Note: We can't just block on the event loop reading the shutdown event
anymore, we need to wait until it read and processed any outstanding
events, so we now send the shutdown event and then block waiting for the
channel to be closed by the event loop.
[NO NEW TESTS NEEDED]
Signed-off-by: Alexander Larsson <alexl@redhat.com>
-rw-r--r-- | libpod/runtime.go | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/libpod/runtime.go b/libpod/runtime.go index f250d759c..0828c19d5 100644 --- a/libpod/runtime.go +++ b/libpod/runtime.go @@ -722,9 +722,10 @@ func (r *Runtime) libimageEvents() { eventChannel := r.libimageRuntime.EventChannel() go func() { + sawShutdown := false for { // Make sure to read and write all events before - // checking if we're about to shutdown. + // shutting down. for len(eventChannel) > 0 { libimageEvent := <-eventChannel e := events.Event{ @@ -739,12 +740,15 @@ func (r *Runtime) libimageEvents() { } } - select { - case <-r.libimageEventsShutdown: + if sawShutdown { + close(r.libimageEventsShutdown) return + } - default: - time.Sleep(100 * time.Millisecond) + select { + case <-r.libimageEventsShutdown: + sawShutdown = true + case <-time.After(100 * time.Millisecond): } } }() @@ -793,7 +797,10 @@ func (r *Runtime) Shutdown(force bool) error { if r.store != nil { // Wait for the events to be written. if r.libimageEventsShutdown != nil { + // Tell loop to shutdown r.libimageEventsShutdown <- true + // Wait for close to signal shutdown + <-r.libimageEventsShutdown } // Note that the libimage runtime shuts down the store. |