Skip to content

cli: perform feature detection lazily - #2424

Merged
silvin-lubecki merged 2 commits into
docker:masterfrom
thaJeztah:lazy_feature_detection
Apr 15, 2020
Merged

cli: perform feature detection lazily#2424
silvin-lubecki merged 2 commits into
docker:masterfrom
thaJeztah:lazy_feature_detection

Conversation

@thaJeztah

@thaJeztahthaJeztah commented Apr 7, 2020

Copy link
Copy Markdown
Member

alternative to / closes#1747
fixes#1739
fixes#2420

cli: perform feature detection lazily

  • Docker build: check experimental --platform on pre-run instead of during intialization
  • Perform feature detection when actually needed, instead of during initializing
  • Version negotiation is performed either when making an API request, or when (e.g.) running docker help (to hide unsupported features)
  • Use a 2 second timeout when 'pinging' the daemon; this should be sufficient for most cases, and when feature detection failed, the daemon will still perform validation (and produce an error if needed)
    • context.WithTimeout() doesn't currently work with ssh connections (connhelper), so we're only applying this timeout for tcp:// connections, otherwise keep the old behavior.

Before this change:

time sh -c 'DOCKER_HOST=tcp://42.42.42.41:4242 docker help &> /dev/null'
real 0m32.919s
user 0m0.370s
sys 0m0.227s
time sh -c 'DOCKER_HOST=tcp://42.42.42.41:4242 docker context ls &> /dev/null'
real 0m32.072s
user 0m0.029s
sys 0m0.023s

After this change:

time sh -c 'DOCKER_HOST=tcp://42.42.42.41:4242 docker help &> /dev/null'
real 0m 2.28s
user 0m 0.03s
sys 0m 0.03s
time sh -c 'DOCKER_HOST=tcp://42.42.42.41:4242 docker context ls &> /dev/null'
real 0m 0.13s
user 0m 0.02s
sys 0m 0.02s

@thaJeztah

Copy link
Copy Markdown
MemberAuthor

@gtardif@silvin-lubecki PTAL

@thaJeztah
thaJeztahforce-pushed the lazy_feature_detection branch 2 times, most recently from 8abec90 to d171265CompareApril 9, 2020 11:27
Comment threadcli/command/image/build.go Outdated
@thaJeztah
thaJeztahforce-pushed the lazy_feature_detection branch from d171265 to 0c08b36CompareApril 9, 2020 16:08
Comment threadcmd/docker/docker.go Outdated
@thaJeztah
thaJeztahforce-pushed the lazy_feature_detection branch 2 times, most recently from 7da559d to e4e3abaCompareApril 9, 2020 19:25
@thaJeztah

Copy link
Copy Markdown
MemberAuthor

@silvin-lubecki updated; PTAL

@silvin-lubeckisilvin-lubecki left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@thaJeztah
thaJeztahforce-pushed the lazy_feature_detection branch 14 times, most recently from bbe201a to 988c619CompareApril 10, 2020 14:31
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
- Perform feature detection when actually needed, instead of during
initializing
- Version negotiation is performed either when making an API request,
or when (e.g.) running `docker help` (to hide unsupported features)
- Use a 2 second timeout when 'pinging' the daemon; this should be
sufficient for most cases, and when feature detection failed, the
daemon will still perform validation (and produce an error if needed)
- context.WithTimeout doesn't currently work with ssh connections (connhelper),
so we're only applying this timeout for tcp:// connections, otherwise
keep the old behavior.
Before this change:
time sh -c 'DOCKER_HOST=tcp://42.42.42.41:4242 docker help &> /dev/null'
real 0m32.919s
user 0m0.370s
sys 0m0.227s
time sh -c 'DOCKER_HOST=tcp://42.42.42.41:4242 docker context ls &> /dev/null'
real 0m32.072s
user 0m0.029s
sys 0m0.023s
After this change:
time sh -c 'DOCKER_HOST=tcp://42.42.42.41:4242 docker help &> /dev/null'
real 0m 2.28s
user 0m 0.03s
sys 0m 0.03s
time sh -c 'DOCKER_HOST=tcp://42.42.42.41:4242 docker context ls &> /dev/null'
real 0m 0.13s
user 0m 0.02s
sys 0m 0.02s
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah
thaJeztahforce-pushed the lazy_feature_detection branch from 988c619 to b397391CompareApril 10, 2020 14:33

@gtardifgtardif left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@silvin-lubeckisilvin-lubecki left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

Sign up for freeto 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.

Docker Desktop on Windows: 'docker context inspect' is very slow Docker commands take 1 minute to timeout if context endpoint is unreachable

3 participants

@thaJeztah@gtardif@silvin-lubecki