mirror of
https://github.com/containers/podman.git
synced 2025-05-17 15:18:43 +08:00
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> Signed-off-by: tomsweeneyredhat <tsweeney@redhat.com>
This commit is contained in:

committed by
tomsweeneyredhat

parent
d520a5ccab
commit
1f24b4fcd9
@ -833,9 +833,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{
|
||||
@ -850,12 +851,15 @@ func (r *Runtime) libimageEvents() {
|
||||
}
|
||||
}
|
||||
|
||||
if sawShutdown {
|
||||
close(r.libimageEventsShutdown)
|
||||
return
|
||||
}
|
||||
|
||||
select {
|
||||
case <-r.libimageEventsShutdown:
|
||||
return
|
||||
|
||||
default:
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
sawShutdown = true
|
||||
case <-time.After(100 * time.Millisecond):
|
||||
}
|
||||
}
|
||||
}()
|
||||
@ -904,7 +908,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.
|
||||
|
Reference in New Issue
Block a user