damccorm opened a new pull request, #41686:
URL: https://github.com/apache/beam/pull/41686
Note: this PR was auto-generated by tooling. Before moving it out of draft,
the author has done a full review of the PR, specifically evaluating it on the
following criteria:
- The PR is an appropriate fix for the issue (e.g. we're not changing a test
to avoid a bug)
- The PR is a simple fix to the issue (e.g. we're not adding infra when we
could just modify a test)
- The PR is not covering for other problems (e.g. if we're bumping timeouts,
it is not because we're covering for a performance problem)
Full details of the methodology of generation and review can be found here -
https://docs.google.com/document/d/14lj7ECVov4T4EdwmIzNlWrRGE3lLDMOwX5xUMGzaLoc/edit?usp=sharing
If you have concerns with the PR or with the underlying methodology used to
generate this, please comment below - they will be addressed by the author not
the tooling :)
### Summary
Serializes `PrismJobServer._install_from_source()` across both threads and
processes using a class-level `threading.Lock` and `fasteners.InterProcessLock`
on `<BIN_CACHE>/prism.install.lock`.
### Root Cause
Observed in [`PreCommit Python ML tests with ML deps installed` run
45645357859](https://github.com/apache/beam/actions/runs/45645357859) across
Python 3.11, 3.12, and 3.13 (and on PR run
[45645095313](https://github.com/apache/beam/actions/runs/45645095313)):
When running a development version of Beam (`'.dev' in version`),
`PrismJobServer._install_from_source()` invokes `go install
github.com/apache/beam/sdks/v2/go/cmd/prism` with
`GOBIN=PrismJobServer.BIN_CACHE` without any cross-process or thread
synchronization. When multiple processes start Prism concurrently (such as all
6 `pytest-xdist` workers on a cold CI runner), all workers launch full `go
install` builds simultaneously against the same Go cache and `GOBIN` target,
thrashing CPU/disk I/O until tests hit the 600s `pytest-timeout` (and starving
the runner).
## Production Impact
Affects developers and users running concurrent `PrismRunner` pipelines or
parallel test workers against a development/source checkout of Apache Beam
(`'.dev'` version): concurrent `go install` processes contend heavily on CPU
and Go build cache, can race writing `<BIN_CACHE>/prism`, and can time out on
cold builds. Serializing builds with `threading.Lock` +
`fasteners.InterProcessLock` lets the first worker compile Prism cleanly at
full speed and populate the Go build cache so subsequent workers' `go install`
checks finish in <1s while still picking up any local Go source edits.
### Fix
- In `sdks/python/apache_beam/runners/portability/prism_runner.py`:
- Ensure `PrismJobServer.BIN_CACHE` exists (`os.makedirs(...,
exist_ok=True)`).
- Guard `PrismJobServer._install_from_source()` (both the local module `go
install` and the `@latest` fallback) with `PrismJobServer._install_lock`
(`threading.Lock`) and
`fasteners.InterProcessLock(os.path.join(PrismJobServer.BIN_CACHE,
'prism.install.lock'))`. Using both locks ensures POSIX `fcntl`-backed
`InterProcessLock` is also safe across threads within the same process.
- In `sdks/python/apache_beam/runners/portability/prism_runner_test.py`:
- Add
`PrismJobServerTest.test_install_from_source_serializes_concurrent_calls`
verifying concurrent callers acquire `InterProcessLock` at
`<BIN_CACHE>/prism.install.lock` sequentially with `max_active_builds == 1`.
### Verification
- Local:
- `pytest apache_beam/runners/portability/prism_runner_test.py -k
"PrismJobServerTest or PrismRunnerSingletonTest"` (24 passed)
- `yapf==0.43.0 --style setup.cfg --diff` clean
- CI: triggering `.github/workflows/beam_PreCommit_Python_ML.yml` on this PR
branch.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]