Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid a HEAD request for each layer in a v2 pull #18418

Merged
merged 1 commit into from Dec 4, 2015

Conversation

aaronlehmann
Copy link
Contributor

We were calling Stat for each layer to get the size so we could indicate
progress, but distribution/distribution#1226 made it
possible to get the length from the GET request that Open initiates.

Saving one round-trip per layer should make pull operations slightly
faster and more robust.

@aaronlehmann
Copy link
Contributor Author

Note that the diff is a bit deceptive. This is simply removing:

    desc, err := blobs.Stat(context.Background(), di.digest)
    if err != nil {
        logrus.Debugf("Error statting layer: %v", err)
        di.err <- err
        return
    }
    di.size = desc.Size

and adding, after the Open:

    di.size, err = layerDownload.Seek(0, os.SEEK_END)
    if err != nil {
        di.err <- err
        return
    }
    _, err = layerDownload.Seek(0, os.SEEK_SET)
    if err != nil {
        di.err <- err
        return
    }

The diff captures the change in a more confusing way.

@thaJeztah
Copy link
Member

Nice!

@cpuguy83
Copy link
Member

cpuguy83 commented Dec 4, 2015

LGTM

We were calling Stat for each layer to get the size so we could indicate
progress, but distribution/distribution#1226 made it
possible to get the length from the GET request that Open initiates.

Saving one round-trip per layer should make pull operations slightly
faster and more robust.

Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
@aaronlehmann
Copy link
Contributor Author

It just occurred to me that the first seek failing (presumably because there's no Content-Length header) shouldn't fail the whole download. It can still continue, but the progress output won't show a progress bar. I'm not sure if this will ever happen in practice, but it seems like a good idea to be robust to this situation.

Sorry for changing the commit after a LGTM.

@aaronlehmann
Copy link
Contributor Author

As a side effect, this tweak made the diff a lot easier to read ;)

@tonistiigi
Copy link
Member

LGTM

1 similar comment
@calavera
Copy link
Contributor

calavera commented Dec 4, 2015

LGTM

calavera added a commit that referenced this pull request Dec 4, 2015
Avoid a HEAD request for each layer in a v2 pull
@calavera calavera merged commit 82c4708 into moby:master Dec 4, 2015
@aaronlehmann aaronlehmann deleted the no-head-requests branch December 4, 2015 23:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants