From 5b71070e421b7491bfc9046dea1ae94888cbb6d4 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Thu, 6 Oct 2022 17:49:00 +0200 Subject: 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 --- libpod/runtime.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'libpod/runtime.go') 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. -- cgit v1.2.3-54-g00ecf