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
1 changed files with 19 additions and 5 deletions

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>
// This is a wrapper for register
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) {
return fmt.Errorf("Container is already loaded")
}
@ -165,7 +171,14 @@ func (daemon *Daemon) Register(container *Container) error {
}
// done
daemon.containers.PushBack(container)
daemon.idIndex.Add(container.ID)
// 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)
} else {
daemon.idIndex.AddWithoutSuffixarrayUpdate(container.ID)
}
// 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
@ -329,8 +342,8 @@ func (daemon *Daemon) restore() error {
}
}
register := func(container *Container) {
if err := daemon.Register(container); err != nil {
registerContainer := func(container *Container) {
if err := daemon.register(container, false); err != nil {
utils.Debugf("Failed to register container %s: %s", container.ID, err)
}
}
@ -342,7 +355,7 @@ func (daemon *Daemon) restore() error {
}
e := entities[p]
if container, ok := containers[e.ID()]; ok {
register(container)
registerContainer(container)
delete(containers, e.ID())
}
}
@ -359,9 +372,10 @@ func (daemon *Daemon) restore() error {
if _, err := daemon.containerGraph.Set(container.Name, container.ID); err != nil {
utils.Debugf("Setting default id - %s", err)
}
register(container)
registerContainer(container)
}
daemon.idIndex.UpdateSuffixarray()
if os.Getenv("DEBUG") == "" && os.Getenv("TEST") == "" {
fmt.Printf(": done.\n")
}