Skip to content

Commit

Permalink
libpod: Remove 100msec delay during shutdown
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
alexlarsson committed Oct 7, 2022
1 parent 13a1c55 commit 5b71070
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions libpod/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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):
}
}
}()
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 5b71070

Please sign in to comment.