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

Expose a large number of ports should not slow down builder #9122

Merged
merged 5 commits into from
Dec 16, 2014

Conversation

dqminh
Copy link
Contributor

@dqminh dqminh commented Nov 12, 2014

Related to #9021

This improves the behavior of builder when handling a (large) list of ports by preallocating some data when possible. It improves the build speed of https://gist.github.com/karalabe/451f01479f8848973331#file-dockerfile from 20+ seconds to a few seconds on my machine

EXPOSE order now will also be more resistant to change as we sort the ports before saving them as image's config.

cc @erikh

Whenever a command arguments is formed by a large linked list, repeatedly
appending to arguments and displayed messages took a long time because go will
have to allocate/copy a lot of times.

This speeds up the allocation by preallocate arrays of correct size for args
and msg

Docker-DCO-1.1-Signed-off-by: Daniel, Dao Quang Minh <dqminh89@gmail.com> (github: dqminh)
Docker-DCO-1.1-Signed-off-by: Daniel, Dao Quang Minh <dqminh89@gmail.com> (github: dqminh)
changing order of EXPOSE ports should not invalidate the cache as the content
doesnt change

Docker-DCO-1.1-Signed-off-by: Daniel, Dao Quang Minh <dqminh89@gmail.com> (github: dqminh)
Saving ports as `map[nat.Port]struct{}` directly has ordering issue which is
more replicatable where we expose a huge number of ports at the same time. As a
result, the cache will be burst whenever the map order is different from the
previous build.
This sorts the ports first and save them as a whitespace-separated list instead
of the map representation, so the order will always be consistent if the port
list isnt changed.

NOTICE: this will burst the old expose caches

Docker-DCO-1.1-Signed-off-by: Daniel, Dao Quang Minh <dqminh89@gmail.com> (github: dqminh)
@erikh
Copy link
Contributor

erikh commented Nov 12, 2014

looks good, but I would like to see https://gist.github.com/karalabe/451f01479f8848973331#file-dockerfile in test form somehow instead of what you currently have. I imagine making parser tests won't work, so maybe you could make an integration-cli test that allocates the range of 1-65535 and then ensures that's in the expose list?

@erikh
Copy link
Contributor

erikh commented Nov 12, 2014

Oh. Don't actually include the file. Generate it, please. :)

@erikh
Copy link
Contributor

erikh commented Nov 12, 2014

One last thing: drone is not passing currently, but I don't believe that's your fault. It'll have to pass, though, before we can merge it.

// instead of using ports directly, we build a list of ports and sort it so
// the order is consistent. This prevents cache burst where map ordering
// changes between builds
portList := make([]string, len(ports))
Copy link
Contributor

Choose a reason for hiding this comment

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

Just idea: probably portList := make([]string, 0, len(ports)) and append allow you to drop i var and have same performance, but I'm not sure.

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 think that's faster than the old way, but allocating a fixed length slice is still the fastest and append has some extra overhead. I wrote a sample program to benchmark here http://play.golang.org/p/dbG3JseujF

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks, nice to know.

this test checks if exposing a large number of ports in Dockerfile properly
saves the port in configs. We dont actually expose a VERY large number of ports
here because the result is the same and it increases the test time by a few
seconds

Docker-DCO-1.1-Signed-off-by: Daniel, Dao Quang Minh <dqminh89@gmail.com> (github: dqminh)
@dqminh
Copy link
Contributor Author

dqminh commented Nov 13, 2014

looks good, but I would like to see https://gist.github.com/karalabe/451f01479f8848973331#file-dockerfile in test form somehow instead of what you currently have. I imagine making parser tests won't work, so maybe you could make an integration-cli test that allocates the range of 1-65535 and then ensures that's in the expose list?

@erikh i added a test but only expose 1-5000 ports. I guess that should be enough since exposing more ports will take more time but probably will not buy us anything more.

@erikh
Copy link
Contributor

erikh commented Nov 13, 2014

SGTM

On Nov 13, 2014, at 10:32 AM, Daniel, Dao Quang Minh notifications@github.com wrote:

looks good, but I would like to see https://gist.github.com/karalabe/451f01479f8848973331#file-dockerfile https://gist.github.com/karalabe/451f01479f8848973331#file-dockerfile in test form somehow instead of what you currently have. I imagine making parser tests won't work, so maybe you could make an integration-cli test that allocates the range of 1-65535 and then ensures that's in the expose list?

@erikh https://github.com/erikh i added a test but only expose 1-5000 ports. I guess that should be enough since exposing more ports will take more time but probably will not buy us anything more.


Reply to this email directly or view it on GitHub #9122 (comment).

@icecrime
Copy link
Contributor

Collective LGTM!

icecrime pushed a commit that referenced this pull request Dec 16, 2014
Expose a large number of ports should not slow down builder
@icecrime icecrime merged commit a76f7c6 into moby:master Dec 16, 2014
@jessfraz
Copy link
Contributor

LGTM

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.

None yet

5 participants