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

docker info: skip API connection if possible #3179

Merged
merged 1 commit into from
Jul 7, 2021

Conversation

thaJeztah
Copy link
Member

The docker info output contains both "local" and "remote" (daemon-side) information.
The API endpoint to collect daemon information (/info) is known to be "heavy",
and (depending on what information is needed) not needed.

This patch checks if the template (--format) used requires information from the
daemon, and if not, omits making an API request.

This will improve performance if (for example), the current "context" is requested
from docker info or if only plugin information is requested.

Before:

time docker info --format '{{range  .ClientInfo.Plugins}}Plugin: {{.Name}}, {{end}}'
Plugin: buildx, Plugin: compose, Plugin: scan,

________________________________________________________
Executed in  301.91 millis    fish           external
   usr time  168.64 millis   82.00 micros  168.56 millis
   sys time  113.72 millis  811.00 micros  112.91 millis

time docker info --format '{{json .ClientInfo.Plugins}}'

time docker info --format '{{.ClientInfo.Context}}'
default

________________________________________________________
Executed in  334.38 millis    fish           external
   usr time  177.23 millis   93.00 micros  177.13 millis
   sys time  124.90 millis  927.00 micros  123.97 millis

docker context use remote-ssh-daemon
time docker info --format '{{.ClientInfo.Context}}'
remote-ssh-daemon

________________________________________________________
Executed in    1.22 secs   fish           external
   usr time  116.93 millis  110.00 micros  116.82 millis
   sys time  144.36 millis  887.00 micros  143.47 millis

And daemon logs:

Jul 06 12:42:12 remote-ssh-daemon dockerd[14377]: time="2021-07-06T12:42:12.139529947Z" level=debug msg="Calling HEAD /_ping"
Jul 06 12:42:12 remote-ssh-daemon dockerd[14377]: time="2021-07-06T12:42:12.140772052Z" level=debug msg="Calling HEAD /_ping"
Jul 06 12:42:12 remote-ssh-daemon dockerd[14377]: time="2021-07-06T12:42:12.163832016Z" level=debug msg="Calling GET /v1.41/info"

After:

time ./build/docker info --format '{{range  .ClientInfo.Plugins}}Plugin: {{.Name}}, {{end}}'
Plugin: buildx, Plugin: compose, Plugin: scan,

________________________________________________________
Executed in  139.84 millis    fish           external
   usr time   76.53 millis   62.00 micros   76.46 millis
   sys time   69.25 millis  723.00 micros   68.53 millis

time ./build/docker info --format '{{.ClientInfo.Context}}'
default

________________________________________________________
Executed in  136.94 millis    fish           external
   usr time   74.61 millis   74.00 micros   74.54 millis
   sys time   65.77 millis  858.00 micros   64.91 millis

docker context use remote-ssh-daemon
time ./build/docker info --format '{{.ClientInfo.Context}}'
remote-ssh-daemon

________________________________________________________
Executed in    1.02 secs   fish           external
   usr time   74.25 millis   76.00 micros   74.17 millis
   sys time   65.09 millis  643.00 micros   64.44 millis

And daemon logs:

Jul 06 12:42:55 remote-ssh-daemon dockerd[14377]: time="2021-07-06T12:42:55.313654687Z" level=debug msg="Calling HEAD /_ping"
Jul 06 12:42:55 remote-ssh-daemon dockerd[14377]: time="2021-07-06T12:42:55.314811624Z" level=debug msg="Calling HEAD /_ping"

- Description for the changelog

Improve performance of `docker info` if a custom `--format` is used that only uses local information. Previously, the `docker info` command would unconditionally make an API call to request daemon system information. With this change, the CLI only uses the daemon API if it detects that information from the daemon is needed.

- A picture of a cute animal (not mandatory but encouraged)

@codecov-commenter
Copy link

codecov-commenter commented Jul 6, 2021

Codecov Report

Merging #3179 (d738e7c) into master (d7a311b) will increase coverage by 0.01%.
The diff coverage is 57.89%.

@@            Coverage Diff             @@
##           master    #3179      +/-   ##
==========================================
+ Coverage   57.06%   57.08%   +0.01%     
==========================================
  Files         299      299              
  Lines       18742    18756      +14     
==========================================
+ Hits        10696    10707      +11     
- Misses       7176     7178       +2     
- Partials      870      871       +1     

The docker info output contains both "local" and "remote" (daemon-side) information.
The API endpoint to collect daemon information (`/info`) is known to be "heavy",
and (depending on what information is needed) not needed.

This patch checks if the template (`--format`) used requires information from the
daemon, and if not, omits making an API request.

This will improve performance if (for example), the current "context" is requested
from `docker info` or if only plugin information is requested.

Before:

    time docker info --format '{{range  .ClientInfo.Plugins}}Plugin: {{.Name}}, {{end}}'
    Plugin: buildx, Plugin: compose, Plugin: scan,

    ________________________________________________________
    Executed in  301.91 millis    fish           external
       usr time  168.64 millis   82.00 micros  168.56 millis
       sys time  113.72 millis  811.00 micros  112.91 millis

    time docker info --format '{{json .ClientInfo.Plugins}}'

    time docker info --format '{{.ClientInfo.Context}}'
    default

    ________________________________________________________
    Executed in  334.38 millis    fish           external
       usr time  177.23 millis   93.00 micros  177.13 millis
       sys time  124.90 millis  927.00 micros  123.97 millis

    docker context use remote-ssh-daemon
    time docker info --format '{{.ClientInfo.Context}}'
    remote-ssh-daemon

    ________________________________________________________
    Executed in    1.22 secs   fish           external
       usr time  116.93 millis  110.00 micros  116.82 millis
       sys time  144.36 millis  887.00 micros  143.47 millis

And daemon logs:

    Jul 06 12:42:12 remote-ssh-daemon dockerd[14377]: time="2021-07-06T12:42:12.139529947Z" level=debug msg="Calling HEAD /_ping"
    Jul 06 12:42:12 remote-ssh-daemon dockerd[14377]: time="2021-07-06T12:42:12.140772052Z" level=debug msg="Calling HEAD /_ping"
    Jul 06 12:42:12 remote-ssh-daemon dockerd[14377]: time="2021-07-06T12:42:12.163832016Z" level=debug msg="Calling GET /v1.41/info"

After:

    time ./build/docker info --format '{{range  .ClientInfo.Plugins}}Plugin: {{.Name}}, {{end}}'
    Plugin: buildx, Plugin: compose, Plugin: scan,

    ________________________________________________________
    Executed in  139.84 millis    fish           external
       usr time   76.53 millis   62.00 micros   76.46 millis
       sys time   69.25 millis  723.00 micros   68.53 millis

    time ./build/docker info --format '{{.ClientInfo.Context}}'
    default

    ________________________________________________________
    Executed in  136.94 millis    fish           external
       usr time   74.61 millis   74.00 micros   74.54 millis
       sys time   65.77 millis  858.00 micros   64.91 millis

    docker context use remote-ssh-daemon
    time ./build/docker info --format '{{.ClientInfo.Context}}'
    remote-ssh-daemon

    ________________________________________________________
    Executed in    1.02 secs   fish           external
       usr time   74.25 millis   76.00 micros   74.17 millis
       sys time   65.09 millis  643.00 micros   64.44 millis

And daemon logs:

    Jul 06 12:42:55 remote-ssh-daemon dockerd[14377]: time="2021-07-06T12:42:55.313654687Z" level=debug msg="Calling HEAD /_ping"
    Jul 06 12:42:55 remote-ssh-daemon dockerd[14377]: time="2021-07-06T12:42:55.314811624Z" level=debug msg="Calling HEAD /_ping"

Signed-off-by: Sebastiaan van Stijn <[email protected]>
@thaJeztah
Copy link
Member Author

@StefanScherer
Copy link
Member

Looks good and makes sense.

I wonder if we could avoid any connection to docker daemon in such cases? 😃
Then listing the plugins would be totally independent from a running engine or not.

@thaJeztah
Copy link
Member Author

Yes, looking at that; the /_ping call is done elsewhere (during initialization); I have a branch that removes it, but ISTR we removed it before, and there was some reason it had to be done there.

Won't do that as part of this PR (for that reason)

Copy link
Member

@StefanScherer StefanScherer left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@silvin-lubecki silvin-lubecki left a comment

Choose a reason for hiding this comment

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

LGTM

@silvin-lubecki silvin-lubecki merged commit 5f07d7d into docker:master Jul 7, 2021
@thaJeztah thaJeztah deleted the optimize_info branch July 7, 2021 09:45
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.

4 participants