Skip to content

Commit 5b71070

Browse files
committed
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 <[email protected]>
1 parent 13a1c55 commit 5b71070

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

libpod/runtime.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -722,9 +722,10 @@ func (r *Runtime) libimageEvents() {
722722

723723
eventChannel := r.libimageRuntime.EventChannel()
724724
go func() {
725+
sawShutdown := false
725726
for {
726727
// Make sure to read and write all events before
727-
// checking if we're about to shutdown.
728+
// shutting down.
728729
for len(eventChannel) > 0 {
729730
libimageEvent := <-eventChannel
730731
e := events.Event{
@@ -739,12 +740,15 @@ func (r *Runtime) libimageEvents() {
739740
}
740741
}
741742

742-
select {
743-
case <-r.libimageEventsShutdown:
743+
if sawShutdown {
744+
close(r.libimageEventsShutdown)
744745
return
746+
}
745747

746-
default:
747-
time.Sleep(100 * time.Millisecond)
748+
select {
749+
case <-r.libimageEventsShutdown:
750+
sawShutdown = true
751+
case <-time.After(100 * time.Millisecond):
748752
}
749753
}
750754
}()
@@ -793,7 +797,10 @@ func (r *Runtime) Shutdown(force bool) error {
793797
if r.store != nil {
794798
// Wait for the events to be written.
795799
if r.libimageEventsShutdown != nil {
800+
// Tell loop to shutdown
796801
r.libimageEventsShutdown <- true
802+
// Wait for close to signal shutdown
803+
<-r.libimageEventsShutdown
797804
}
798805

799806
// Note that the libimage runtime shuts down the store.

0 commit comments

Comments
 (0)