mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
Refactor libcontainerd to minimize c8d RPCs
The containerd client is very chatty at the best of times. Because the libcontained API is stateless and references containers and processes by string ID for every method call, the implementation is essentially forced to use the containerd client in a way which amplifies the number of redundant RPCs invoked to perform any operation. The libcontainerd remote implementation has to reload the containerd container, task and/or process metadata for nearly every operation. This in turn amplifies the number of context switches between dockerd and containerd to perform any container operation or handle a containerd event, increasing the load on the system which could otherwise be allocated to workloads. Overhaul the libcontainerd interface to reduce the impedance mismatch with the containerd client so that the containerd client can be used more efficiently. Split the API out into container, task and process interfaces which the consumer is expected to retain so that libcontainerd can retain state---especially the analogous containerd client objects---without having to manage any state-store inside the libcontainerd client. Signed-off-by: Cory Snider <csnider@mirantis.com>
This commit is contained in:
@@ -74,19 +74,28 @@ func (daemon *Daemon) update(name string, hostConfig *container.HostConfig) erro
|
||||
ctr.UpdateMonitor(hostConfig.RestartPolicy)
|
||||
}
|
||||
|
||||
defer daemon.LogContainerEvent(ctr, "update")
|
||||
|
||||
// If container is not running, update hostConfig struct is enough,
|
||||
// resources will be updated when the container is started again.
|
||||
// If container is running (including paused), we need to update configs
|
||||
// to the real world.
|
||||
if ctr.IsRunning() && !ctr.IsRestarting() {
|
||||
if err := daemon.containerd.UpdateResources(context.Background(), ctr.ID, toContainerdResources(hostConfig.Resources)); err != nil {
|
||||
restoreConfig = true
|
||||
// TODO: it would be nice if containerd responded with better errors here so we can classify this better.
|
||||
return errCannotUpdate(ctr.ID, errdefs.System(err))
|
||||
}
|
||||
ctr.Lock()
|
||||
isRestarting := ctr.Restarting
|
||||
tsk, err := ctr.GetRunningTask()
|
||||
ctr.Unlock()
|
||||
if errdefs.IsConflict(err) || isRestarting {
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
daemon.LogContainerEvent(ctr, "update")
|
||||
if err := tsk.UpdateResources(context.TODO(), toContainerdResources(hostConfig.Resources)); err != nil {
|
||||
restoreConfig = true
|
||||
// TODO: it would be nice if containerd responded with better errors here so we can classify this better.
|
||||
return errCannotUpdate(ctr.ID, errdefs.System(err))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user