Skip to content

batches: use Docker CPU count as default parallelism, not GOMAXPROCS#786

Merged
LawnGnome merged 11 commits into
mainfrom
aharvey/cpu-count
Jun 16, 2022
Merged

batches: use Docker CPU count as default parallelism, not GOMAXPROCS#786
LawnGnome merged 11 commits into
mainfrom
aharvey/cpu-count

Conversation

@LawnGnome

@LawnGnome LawnGnome commented Jun 15, 2022

Copy link
Copy Markdown
Contributor

This PR changes the default parallelism of src batch preview|apply runs to be based on the CPU cores reported by docker info.

Practically, this means that Docker Desktop users will now have their parallelism based on the VM Docker runs within, not their host machine. The trade off here is that Docker Desktop users will likely have their default parallelism cut significantly, but this is also likely to make issues caused by the Docker VM having its resources exhausted considerably less likely.

Implementation notes

  • I've migrated the previous docker version preflight to use docker info instead, which means we can get the CPU count and preflight Docker at the same time.
  • Since docker info should always be quick, this reuses the same timeout behaviour as docker: use a short timeout when inspecting images #783, which has been renamed from being image inspect specific to being used for any "fast commands" issued to Docker. The behaviour is otherwise unchanged.
  • In testing this, I found an issue where os/exec is inconsistent in terms of the error returned when a deadline is exceeded; I've updated both places we use the fast command context to look both at the returned error and the context error.

Screenshot of the timeout

image

Test plan

Added unit tests, and tested this in various scenarios locally (Docker not running; Docker running but unresponsive; Docker running normally).

@LawnGnome LawnGnome requested a review from a team June 15, 2022 22:20
@LawnGnome LawnGnome marked this pull request as ready for review June 15, 2022 22:20
@LawnGnome LawnGnome self-assigned this Jun 15, 2022
Comment thread cmd/src/batch_exec.go Outdated
SkipErrors: opts.flags.skipErrors,
CleanArchives: opts.flags.cleanArchives,
Parallelism: opts.flags.parallelism,
Parallelism: parallelism,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

fun fact, it's unused in SSBC 😆 PR cleaning this mess here up coming soon :)

defer cancel()

args := []string{"info", "--format", "{{ .NCPU }}"}
out, err := exec.CommandContext(dctx, "docker", args...).CombinedOutput()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

CombinedOutput or Output?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Combined — Docker outputs all non-container-output on stderr.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

interesting!

Comment thread internal/batches/docker/info.go Outdated
Co-authored-by: Erik Seliger <erikseliger@me.com>
@LawnGnome LawnGnome merged commit 524c89a into main Jun 16, 2022
@LawnGnome LawnGnome deleted the aharvey/cpu-count branch June 16, 2022 16:56
scjohns pushed a commit that referenced this pull request Apr 24, 2023
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.

3 participants