Skip to content

improve plugins discovery performance - #4120

Closed
crazy-max wants to merge 1 commit into
docker:masterfrom
crazy-max:fix-perf-reg
Closed

improve plugins discovery performance#4120
crazy-max wants to merge 1 commit into
docker:masterfrom
crazy-max:fix-perf-reg

Conversation

@crazy-max

@crazy-maxcrazy-max commented Mar 25, 2023

Copy link
Copy Markdown
Member

fixes#3621
related to #3429

#3429 adds Cobra completion v2 support for commands and plugins. Since this change every invocation takes ~+60ms.

For docker --version:

CommandMean [ms]Min [ms]Max [ms]Relative
docker-19.03.1561.4 ± 2.657.564.46.56 ± 1.19
docker-20.10.018.0 ± 2.914.621.81.93 ± 0.46
docker-20.10.1217.6 ± 0.916.318.91.88 ± 0.35
docker-20.10.1716.5 ± 1.515.419.11.77 ± 0.35
docker-20.10.2313.9 ± 1.012.715.31.49 ± 0.28
docker-23.0.168.2 ± 2.264.770.37.29 ± 1.31
docker-dev-pr-3419-a4b6fe115.7 ± 0.714.916.51.68 ± 0.30
docker-dev-pr-3429-a09e61a69.3 ± 2.566.773.17.41 ± 1.33

See the diff between docker-dev-pr-3419-a4b6fe1 and docker-dev-pr-3429-a09e61a.

Looking at the changes, we are now loading plugins for every invocation:

cli/cmd/docker/docker.go

Lines 230 to 233 in f5d698a

err=pluginmanager.AddPluginCommandStubs(dockerCli, cmd)
iferr!=nil {
returnerr
}

So the more plugins are in place in the user space, the worst it would be. And we have a lot of them in Docker Desktop atm:

Client:
Context: default
Debug Mode: false
Plugins:
buildx: Docker Buildx (Docker Inc., v0.10.3)
compose: Docker Compose (Docker Inc., v2.15.1)
dev: Docker Dev Environments (Docker Inc., v0.1.0)
extension: Manages Docker extensions (Docker Inc., v0.2.18)
sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc., 0.6.0)
scan: Docker Scan (Docker Inc., v0.25.0)
scout: Command line tool for Docker Scout (Docker Inc., v0.6.0)

- What I did

Instead of removing completion for plugins to fix the regression, we can slightly improve plugins discovery if we want to keep this feature.

We should also look if every plugin we currently ship doesn't introduce performance regressions when invoked through the plugin manager in

returnexec.Command(c.path, MetadataSubcommandName).Output()

/usr/local/lib/docker/cli-plugins/docker-buildx docker-cli-plugin-metadata

I think a benchmark suite here that could be used by our plugins would be good at some point.

- How I did it

Spawn a goroutine for each iteration in the loop when listing plugins.

- How to verify it

Here is the benchmark result (see last row):

CommandMean [ms]Min [ms]Max [ms]Relative
docker-19.03.1561.4 ± 2.657.564.46.56 ± 1.19
docker-20.10.018.0 ± 2.914.621.81.93 ± 0.46
docker-20.10.1217.6 ± 0.916.318.91.88 ± 0.35
docker-20.10.1716.5 ± 1.515.419.11.77 ± 0.35
docker-20.10.2313.9 ± 1.012.715.31.49 ± 0.28
docker-23.0.168.2 ± 2.264.770.37.29 ± 1.31
docker-dev-pr-3419-a4b6fe115.7 ± 0.714.916.51.68 ± 0.30
docker-dev-pr-3429-a09e61a69.3 ± 2.566.773.17.41 ± 1.33
docker-dev-fix-perf-reg32.1 ± 1.330.533.83.43 ± 0.62

- Description for the changelog

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

@codecov-commenter

codecov-commenter commented Mar 25, 2023

Copy link
Copy Markdown

Codecov Report

Merging #4120 (3ffbe4c) into master (f5d698a) will increase coverage by 0.00%.
The diff coverage is 61.90%.

Additional details and impacted files
@@ Coverage Diff @@## master #4120 +/- ##
=======================================
Coverage 59.16% 59.16% =======================================
Files 287 287 Lines 24716 24727 +11 =======================================
+ Hits 14623 14630 +7 - Misses 9209 9212 +3 - Partials 884 885 +1 

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
Sign up for freeto 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.

Performance regression on every command invocation

2 participants

@crazy-max@codecov-commenter