Skip to content

Conversation

unclejack
Copy link
Contributor

This WIP PR makes Docker buffer layers to disk before registering them. This helps speed up the layer download.

Please note that this PR doesn't attempt to do anything about the performance of layer loading. That might still be slow. Registering layers in the graph can still take a long time if the system's performance and disk IO isn't that good.

If this proves to improve performance for some, a flag to bypass the buffering to disk should be added.

The code of the TempFileReader can probably be moved elsewhere.

helps with #7291 by improving pull

func (r *tempFileReader) Read(data []byte) (int, error) {
n, err := r.File.Read(data)
if err != nil {
r.File.Close()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe r.Close()?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's with this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kinda prefer the explicit one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, if you like it. Just thought that you missed this stuff :)

@unclejack
Copy link
Contributor Author

@tianon This is just for testing right now.

@ross-w
Copy link

ross-w commented Aug 24, 2014

@unclejack thanks, but it's no quicker - in fact it's the same speed as it was originally https://gist.github.com/ross-w/407d7cbe3c16c592fbec

The "downloading layer to temp file" (or whatever it is, it's almost too quick for me to read) step is very quick, but the loading layer step takes all the time.

@tianon
Copy link
Member

tianon commented Aug 24, 2014

@unclejack fair enough ❤️

if err != nil {
return nil, err
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think here we need logic to remove tmp on error. Maybe like named returning err and

defer func() {
    if err != nil {
         os.RemoveAll(tmp)
    }
}()

@dmp42 dmp42 mentioned this pull request Aug 25, 2014
@LK4D4
Copy link
Contributor

LK4D4 commented Aug 26, 2014

I've did little test and it is slightly faster for me with my 54 Mb wifi and 5400 HDD on small images.

@tiborvass
Copy link
Contributor

@unclejack For small images I experience an almost-negligible performance improvement (a few seconds), and it's hard for me to make sure it's not too random (I did multiple tries though).
However, doing time docker pull ubuntu:14.04 on master vs this PR rebased on master, I have about 10 sec slow down on average.

So maybe I'm testing it wrong, but from what I can see, I would not want to merge this PR.

@ross-w
Copy link

ross-w commented Aug 26, 2014

@tiborvass this is more or less my experience also, I can't help but feel that this isn't the bottleneck we are experiencing. Though it was very interesting to see how quick the download is compared to all the other stuff, so that definitely points the finger at the non-download parts being slow.

@unclejack
Copy link
Contributor Author

@tiborvass Please try with a local registry. There are some bottlenecks outside of the download and they're going to be fixed by #7542. These two PRs should make pull faster.

@unclejack unclejack force-pushed the buffer_layers_to_disk branch 2 times, most recently from e59d7f5 to 82e7298 Compare August 28, 2014 12:03
Docker-DCO-1.1-Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com> (github: unclejack)
@unclejack unclejack force-pushed the buffer_layers_to_disk branch from 82e7298 to ad23448 Compare September 1, 2014 22:27
@unclejack
Copy link
Contributor Author

@LK4D4 Can you take a look at this PR, please?

@LK4D4
Copy link
Contributor

LK4D4 commented Sep 3, 2014

@unclejack So, we want merge this?

@unclejack
Copy link
Contributor Author

@LK4D4 We need to consider merging this after proper review.

@LK4D4
Copy link
Contributor

LK4D4 commented Sep 3, 2014

Tests passing, code LGTM

@vbatts
Copy link
Contributor

vbatts commented Sep 23, 2014

So this could segregate failures in pulling the images, from the registering of the image (like a race in a failed image being cleaned up before it is usable).

I'm going to try again with a local registry, but just did a few pulls from the hub, and did not ever get better time with this PR than without. Doing a pull of the centos:latest image, I did 1 untimed pull, to ensure the CDN didn't interfere with the result, the:

# build of gh#7704
real    2m29.174s
real    2m31.422s
real    2m26.713s
real    2m22.380s


# build of 1.2.0-dev // ed7fb3b
real    2m20.081s
real    2m14.691s
real    2m16.217s

The times are not so greatly different, but still.

Also, another benefit of having this temp buffering could be one less things to worry about when (if) we reorganize graph for checksum based layer paths.

@vbatts
Copy link
Contributor

vbatts commented Sep 23, 2014

similar when pulling from a local registry

-real    0m19.535s
-real    0m19.823s
-real    0m19.526s
-real    0m19.642s
-real    0m19.645s
-real    0m19.652s
+real    0m24.278s
+real    0m24.195s
+real    0m24.146s
+real    0m24.494s
+real    0m24.228s
+real    0m24.341s

Where all 24s are with this PR, and 19 is from 1.2.0-dev // ed7fb3b

@unclejack
Copy link
Contributor Author

I'm going to close this now. I can open this PR again if we don't change the code in the meantime.

@unclejack unclejack closed this Oct 4, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants