1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

update Suffixarray only once during daemon startup

This commit makes the Docker daemon call UpdateSuffixarray only after
it finishes registering all containers.

This lowers the amount of time required for the Docker daemon to start
up.

Docker-DCO-1.1-Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com> (github: unclejack)
This commit is contained in:
unclejack 2014-05-14 17:58:37 +03:00
parent 219b7ae8b5
commit 5d5c89398c

View file

@ -141,7 +141,13 @@ func (daemon *Daemon) load(id string) (*Container, error) {
} }
// Register makes a container object usable by the daemon as <container.ID> // Register makes a container object usable by the daemon as <container.ID>
// This is a wrapper for register
func (daemon *Daemon) Register(container *Container) error { func (daemon *Daemon) Register(container *Container) error {
return daemon.register(container, true)
}
// register makes a container object usable by the daemon as <container.ID>
func (daemon *Daemon) register(container *Container, updateSuffixarray bool) error {
if container.daemon != nil || daemon.Exists(container.ID) { if container.daemon != nil || daemon.Exists(container.ID) {
return fmt.Errorf("Container is already loaded") return fmt.Errorf("Container is already loaded")
} }
@ -165,7 +171,14 @@ func (daemon *Daemon) Register(container *Container) error {
} }
// done // done
daemon.containers.PushBack(container) daemon.containers.PushBack(container)
// don't update the Suffixarray if we're starting up
// we'll waste time if we update it for every container
if updateSuffixarray {
daemon.idIndex.Add(container.ID) daemon.idIndex.Add(container.ID)
} else {
daemon.idIndex.AddWithoutSuffixarrayUpdate(container.ID)
}
// FIXME: if the container is supposed to be running but is not, auto restart it? // FIXME: if the container is supposed to be running but is not, auto restart it?
// if so, then we need to restart monitor and init a new lock // if so, then we need to restart monitor and init a new lock
@ -329,8 +342,8 @@ func (daemon *Daemon) restore() error {
} }
} }
register := func(container *Container) { registerContainer := func(container *Container) {
if err := daemon.Register(container); err != nil { if err := daemon.register(container, false); err != nil {
utils.Debugf("Failed to register container %s: %s", container.ID, err) utils.Debugf("Failed to register container %s: %s", container.ID, err)
} }
} }
@ -342,7 +355,7 @@ func (daemon *Daemon) restore() error {
} }
e := entities[p] e := entities[p]
if container, ok := containers[e.ID()]; ok { if container, ok := containers[e.ID()]; ok {
register(container) registerContainer(container)
delete(containers, e.ID()) delete(containers, e.ID())
} }
} }
@ -359,9 +372,10 @@ func (daemon *Daemon) restore() error {
if _, err := daemon.containerGraph.Set(container.Name, container.ID); err != nil { if _, err := daemon.containerGraph.Set(container.Name, container.ID); err != nil {
utils.Debugf("Setting default id - %s", err) utils.Debugf("Setting default id - %s", err)
} }
register(container) registerContainer(container)
} }
daemon.idIndex.UpdateSuffixarray()
if os.Getenv("DEBUG") == "" && os.Getenv("TEST") == "" { if os.Getenv("DEBUG") == "" && os.Getenv("TEST") == "" {
fmt.Printf(": done.\n") fmt.Printf(": done.\n")
} }