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

Allow concurrent runs of pants on the same instance of pantsd #11639

Closed

Conversation

stuhood
Copy link
Sponsor Member

@stuhood stuhood commented Mar 5, 2021

Problem

Concurrent execution of multiple runs of pants against the same instance of pantsd were disabled when forking was remove from pantsd. But the v2 engine isolates state and avoids global mutable variables such that concurrent runs could be unblocked by fixing the remaining global stateful cases:

Solution

Now that all global stateful cases are removed, we can remove the lock that prevents concurrent runs in pantsd, and deprecate the --concurrent flag.

Result

Multiple runs of pants can proceed concurrently with the same instance of pantsd in a single workspace. See https://asciinema.org/a/397032 for an example.

Fixes #7654.

…ronment or a new filtered Environment type.

[ci skip-build-wheels]

[ci skip-rust]
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]
@stuhood stuhood force-pushed the stuhood/concurrent-pantsd-runs branch from 10fc4e2 to 288263c Compare March 6, 2021 01:09
@stuhood stuhood requested review from Eric-Arellano, tdyas, jsirois and benjyw and removed request for tdyas March 6, 2021 01:42
@stuhood stuhood marked this pull request as ready for review March 6, 2021 01:42
@stuhood
Copy link
Sponsor Member Author

stuhood commented Mar 6, 2021

Only the top commit is relevant: the rest is #11641.

Copy link
Contributor

@jsirois jsirois left a comment

Choose a reason for hiding this comment

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

Nice.

Copy link
Contributor

@Eric-Arellano Eric-Arellano left a comment

Choose a reason for hiding this comment

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

Epic!

@@ -94,7 +94,7 @@ function run_pex() {
function run_packages_script() {
(
cd "${ROOT}"
./pants --concurrent run "${ROOT}/build-support/bin/packages.py" -- "$@"
./pants --no-pantsd run "${ROOT}/build-support/bin/packages.py" -- "$@"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this?

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

My thinking was that in at least some of these cases the --concurrent flag was actually meant-as "please disable pantsd". This one didn't have a comment to explain why it was being used: since this is a bash script, it didn't seem likely that this script was "running under" pants.

@Eric-Arellano
Copy link
Contributor

This might be related to #11626, but, I ran ./pants test src/python/pants/base: at the same time in two different tabs. Both correctly rendered the console test summary, but only one showed the std{out,err} of the failed exception_sink_integration_test.py. What would you expect? The EnrichedTestResult rule is uncacheable, but I'm not sure how that plays out with concurrent runs.

To reproduce, probably useful to do a slower test (or add time.sleep()) so it doesn't complete before starting the other run.

@stuhood
Copy link
Sponsor Member Author

stuhood commented Mar 7, 2021

This might be related to #11626, but, I ran ./pants test src/python/pants/base: at the same time in two different tabs. Both correctly rendered the console test summary, but only one showed the std{out,err} of the failed exception_sink_integration_test.py. What would you expect? The EnrichedTestResult rule is uncacheable, but I'm not sure how that plays out with concurrent runs.

Mmm, no: this is an oversight: thanks. I had planned to add a test or two before landing this, but I doubt that it would have caught that case.

I have a good idea of how to resolve it though (you're right that it relates to the behavior of uncacheable nodes): will do that as another prework PR.

@stuhood stuhood marked this pull request as draft March 9, 2021 00:32
stuhood added a commit that referenced this pull request Mar 9, 2021
### Problem

In order to allow concurrent runs of Pants in #11639 (part of #7654), all global mutable singletons must be either 1) thread-local, 2) replaced with explicitly passed values. `os.environ` and `sys.argv` are two of the last cases we're concerned with.

### Solution

Although we could hypothetically redefine `os.environ` and `os.getenv` as thread-local, they seem to be a better fit to be explicitly passed. So this change:
1. Renames (and moves) `PantsEnvironment` to `CompleteEnvironment`
2. Adds `Environment` and `EnvironmentRequest`, which filter the `CompleteEnvironment` to a smaller subset, and should be used more frequently by `@rules`.
3. Fixes a few cases of implicit `os.environ` usage in the `PythonSetup` subsystem by explicitly selecting interpreter-selection env vars (`HOME`/`PATH`/`PYENV_ROOT`)

Finally, we empty the environment for `pantsd` runs to enforce explicit usage of `CompleteEnvironment`/`Environment`. 

### Result

The last (?) global mutable variable blocking #7654 is removed. 

[ci skip-build-wheels]
Base automatically changed from master to main March 19, 2021 19:20
@stuhood stuhood closed this Jun 17, 2021
@stuhood
Copy link
Sponsor Member Author

stuhood commented Jun 17, 2021

See #7654 (comment)

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.

Re-enable concurrent runs for pantsd in v2
3 participants