Repository navigation
[ci][doc] Log builder CPU and memory around the RtD Sphinx build - #65631
dstrodtman wants to merge 5 commits into
Conversation
Read the Docs builds have been failing with a bare EOFError raised from multiprocessing/connection.py. The doc Makefile passes -j auto, so Sphinx forks one write worker per CPU, and when a worker dies the parent reports only that EOFError. The log names no document and no cause, and the point in the write phase where it surfaces moves between builds: 58%, 78%, and 92% across three recent failures. Five builds in the last two days failed this way, one of them on master, so the cause is the builder rather than any single PR. Every other RtD failure in that window is an ordinary fail_on_warning trip. The likely mechanism is the kernel OOM-killing a write worker, but confirming it needs numbers the build doesn't currently report: the builder's CPU count, its cgroup memory ceiling, the peak the build reached, and the cgroup OOM counters. Lowering -j without those would slow every doc build and might buy nothing, since the useful cap depends on how many CPUs the builder has. Wrap the existing make invocation so those values print before and after it. The diagnostics run around the build rather than in a post_build job because post_build is skipped on failure, and the failing build is the one worth measuring. rc carries make's exit status through, so a real Sphinx failure still fails the build, and every probe is guarded so a missing file or a non-matching grep can't abort the job. This is a temporary measurement step. Remove the wrapper once the numbers are in and the follow-up fix lands. Signed-off-by: Douglas Strodtman <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request wraps the Sphinx build in .readthedocs.yaml with builder resource diagnostics to troubleshoot intermittent build failures, likely caused by OOM-killing of write workers. The feedback suggests adding clear labels to the printed metrics (such as CPU count and cgroup memory limits) to improve log readability and make troubleshooting easier.
| echo "=== builder capacity ===" | ||
| nproc || true | ||
| grep -E "MemTotal|MemAvailable" /proc/meminfo || true | ||
| cat /sys/fs/cgroup/memory.max 2>/dev/null || echo "no cgroup v2 memory.max" | ||
| cat /sys/fs/cgroup/memory.high 2>/dev/null || echo "no cgroup v2 memory.high" | ||
| rc=0 | ||
| make -C doc html HTMLDIR="$READTHEDOCS_OUTPUT/html" || rc=$? | ||
| echo "=== builder peak, sphinx exit $rc ===" | ||
| cat /sys/fs/cgroup/memory.peak 2>/dev/null || echo "no cgroup v2 memory.peak" | ||
| cat /sys/fs/cgroup/memory.events 2>/dev/null || echo "no cgroup v2 memory.events" | ||
| grep -E "MemAvailable" /proc/meminfo || true | ||
| exit $rc |
There was a problem hiding this comment.
The printed values for nproc, memory.max, memory.high, and memory.peak are raw numbers without labels, which makes the build logs harder to interpret and troubleshoot. Adding clear labels to these metrics improves log readability and maintainability.
echo "=== builder capacity ==="
echo "CPUs: $(nproc 2>/dev/null || echo 'unknown')"
grep -E "MemTotal|MemAvailable" /proc/meminfo || true
if [ -r /sys/fs/cgroup/memory.max ]; then echo "memory.max: $(cat /sys/fs/cgroup/memory.max)"; else echo "memory.max: not found"; fi
if [ -r /sys/fs/cgroup/memory.high ]; then echo "memory.high: $(cat /sys/fs/cgroup/memory.high)"; else echo "memory.high: not found"; fi
rc=0
make -C doc html HTMLDIR="$READTHEDOCS_OUTPUT/html" || rc=$?
echo "=== builder peak, sphinx exit $rc ==="
if [ -r /sys/fs/cgroup/memory.peak ]; then echo "memory.peak: $(cat /sys/fs/cgroup/memory.peak)"; else echo "memory.peak: not found"; fi
cat /sys/fs/cgroup/memory.events 2>/dev/null || echo "no cgroup v2 memory.events"
grep -E "MemAvailable" /proc/meminfo || true
exit $rc|
The first build with this wrapper reproduced the failure and answered the question. Build 4343347, RtD
The builder has 4 CPUs, so It also rules out the cheap non-answer. A cap is worth doing, because Worth noting the ceiling is a per-build cgroup limit rather than host pressure, so this isn't contention from other builds on the same machine. The build simply asks for more than it's allowed. Suggested follow-up, kept separate from this measurement PR: parameterize the job count in |
|
Worth adding why this is new rather than long-standing, because it changes what the right fix is. The RtD build didn't always use if self.project.has_feature(Feature.BUILD_IN_PARALLEL):
build_command.extend(["-j", "auto"])That flag is off by default, so RtD was almost certainly building Ray's docs serially. Neither PR was wrong. They just moved a 4x write-phase memory multiplier onto the one builder with a hard memory ceiling. The ceiling is RtD's standard one, not something that changed under us. What made it start failing in mid-August is growth crossing the line, not a single commit. First So there are two independent levers, and they aren't exclusive:
Given headroom is only about 760 MB and the docs keep growing, doing 1 now and pursuing 2 separately seems right, so the next content addition doesn't put us straight back here. |
The first diagnostic build confirmed the OOM kill and gave a 4-CPU, 7 GB builder with a 5.9 GiB peak, but it left the worker count assumed rather than measured. Sphinx resolves -j auto through multiprocessing.cpu_count, which reports the host's logical CPUs and is neither affinity- nor cgroup-aware. nproc reports the affinity mask instead. If the two disagree, Sphinx forks more write workers than the container has CPUs to run, each carrying its own copy of the environment, and the peak is set by the larger number rather than by the 4 that nproc reported. That distinction also decides whether the abrupt mid-August onset has an explanation. The lock file is fully hash-pinned and unchanged, and the document count moved only from 4058 to 4087 between a passing build on Aug 15 and a failing one on Aug 20, so neither dependencies nor content growth account for it. A change in the host's CPU count would, and it is not visible in any build metadata the API exposes. Print all three counts so they can be compared rather than assumed. Signed-off-by: Douglas Strodtman <[email protected]>
The python -c probe added in the previous commit came back mangled. The job runner strips single quotes from arguments, so the quoted labels became bare names: one printed the function object rather than its label and the next raised NameError before its value was reported. The comment block in this file already warned about that class of quirk. It did answer the question it was added for before failing, reporting 4 where nproc also reported 4, so this builder isn't overcommitting write workers. Keep measuring it per build anyway, since a host with a different CPU count would change the answer, and the abrupt onset has no other explanation on the Ray side: the lock file is hash-pinned and unchanged, and the document count moved only 4058 to 4087 across the window. nproc and nproc --all give the same affinity-versus-installed comparison without any quoting for the runner to strip. Signed-off-by: Douglas Strodtman <[email protected]>
|
Correcting part of my earlier comment. I attributed the mid-August onset to growth crossing the memory ceiling. That doesn't hold up, and two more builds since have narrowed things further. Content growth isn't it. The Sphinx environment went from 4058 documents on a passing Aug 15 Dependency drift isn't it either. The builder isn't overcommitting workers. The concern behind the CPU probe was that Sphinx resolves And my "onset Aug 19" claim was not statistically meaningful. The What the two newest builds show is that this is marginal rather than threshold-crossing. Build 4343476 passed with What stands from the earlier comment is the structural part: That doesn't change the remediation, and if anything it strengthens the case for capping the job count on the RtD path, since there's no threshold to get back under. It's the one lever that creates real headroom rather than restoring a margin that was never comfortable. |
Parameterize the Sphinx job count as SPHINX_JOBS, defaulting to auto so nothing changes for existing callers, and add a temporary paired measurement to the Read the Docs html job. The job count needs to come down on the memory-capped RtD builder, where four write workers each carry their own copy of the environment against a 7 GB ceiling. Picking a value blind trades wall clock on every doc build for headroom, so measure the trade first. Between-build comparison cannot resolve it. The html job for the same full clean build ranges from 368 to 562 seconds across recent master builds, a spread far larger than the effect being measured. So the html job runs the build twice within one job, once at the default and once at SPHINX_JOBS=2, which cancels the between-builder variance. Epoch seconds print around each arm, and memory.peak is reset between them where the kernel allows, giving a per-arm peak as well as a per-arm duration. Both arms are full clean builds, since SPHINXOPTS carries -a -E, so neither reuses the other environment. The remaining confound is order, because the second arm starts with a warm page cache, so a following run reverses the arms. The doubled job may approach the build time limit. The job exits on arm A's status, so the published output and the pass or fail signal still come from the default configuration. The measurement wrapper comes back out before this merges. The SPHINX_JOBS parameter stays, since the follow-up fix sets it from .readthedocs.yaml. Signed-off-by: Douglas Strodtman <[email protected]>
The paired run answered the cost question and exposed a gap. On one builder the same full clean build took 349 seconds at -j auto and 620 seconds at SPHINX_JOBS=2, so halving the job count costs about 78 percent more wall clock. That is a lower bound, since the second arm ran with a warm page cache, which favors it. What the paired run could not measure is the saving that cost is meant to buy. memory.peak turned out not to be resettable on this kernel, so the reading taken after each arm was one high-water mark across both rather than a figure per arm. Both reads returned the same value, which is arm A's peak. Drop to a single arm at SPHINX_JOBS=2 so memory.peak describes that configuration alone. Peak memory is far more stable across builders than duration, with three runs at -j auto landing within 180 MB of each other, so one clean sample is worth more here than another paired comparison. Signed-off-by: Douglas Strodtman <[email protected]>
## Summary
Read the Docs builds intermittently fail with a bare `EOFError` and no
failing document named:
```
File ".../multiprocessing/connection.py", line 399, in _recv
raise EOFError
EOFError
make: *** [Makefile:91: html] Error 2
```
The kernel OOM-kills one of Sphinx's parallel write workers, and the
parent process has nothing better to report than the broken pipe. This
caps the worker count on the Read the Docs builder, which is the only
builder with a hard memory ceiling.
Two changes:
- `doc/Makefile` gains `SPHINX_JOBS ?= auto`, feeding `sphinx-build -j`.
The default keeps today's behavior for every existing caller.
- The `.readthedocs.yaml` html job passes `SPHINX_JOBS=2`.
## The mechanism
The builder has 4 CPUs and a cgroup `memory.max` of 7,130,316,800 bytes,
about 6.64 GiB, which matches the memory limit Read the Docs documents
for Business. `-j auto` forks one write worker per CPU and each worker
carries its own copy of the build environment, so the write phase costs
memory in proportion to the job count.
Measured on the builder, with `memory.events` read immediately after the
build:
| Job count | `memory.peak` | Headroom under the ceiling | `oom_kill` |
Result |
|---|---|---|---|---|
| `auto` (4) | 6,371,254,272 | ~759 MB | 1 | failed, `EOFError` |
| `auto` (4) | 6,503,370,752 | ~627 MB | 0 | passed |
| 2 | 5,566,427,136 | ~1,564 MB | 0 | passed |
The two `-j auto` rows are the important pair: the run that was killed
peaked *lower* than the run that passed. There is no threshold being
crossed. The build simply runs about 600 MB under a hard ceiling with
four workers allocating independently, and whether a given run survives
depends on the timing of individual allocations. That is also why the
document Sphinx dies on moves between builds, which is what makes the
failure read as a content problem when it isn't.
Dropping to 2 workers roughly doubles the headroom, from about 600 MB to
about 1.5 GiB.
## Why this is worth doing rather than waiting
The parallelism is recent, not long-standing. Read the Docs' own Sphinx
invocation adds `-j auto` only for projects carrying the opt-in
`BUILD_IN_PARALLEL` feature flag, so RtD was building Ray's docs
serially. #64277 pointed `build.jobs.build.html` at `make -C doc html`,
which inherited the Makefile's `-j auto` — a flag that until then only
the Buildkite doc build used. #64599 then made every preview a full
clean `-a -E` build. Neither change was wrong on its own; together they
put four write workers and a thin memory margin on the one builder that
can't absorb them.
Some things that this is *not*, all checked:
- **Not content growth.** The Sphinx environment went from 4058
documents on a passing build to 4087 on a failing one. 0.7% can't move a
build across a ceiling.
- **Not dependency drift.** `doc/requirements-doc.lock.txt` is fully
hash-pinned and unchanged across the window.
- **Not worker overcommit.** Sphinx resolves `-j auto` through
`multiprocessing.cpu_count`, which is neither affinity- nor
cgroup-aware, so it can in principle fork more workers than the
container can run. On this builder `nproc` and `nproc --all` both report
4, so that isn't happening.
- **Not host contention.** The ceiling is a per-build cgroup limit, not
host pressure, so this isn't other builds crowding the machine.
## Cost
Wall clock. A paired run on one builder measured 349 seconds at `-j
auto` against 620 seconds at `SPHINX_JOBS=2`, about 78% slower. The
`SPHINX_JOBS=2` arm ran with a warm cache, so treat 78% as a lower
bound.
That cost is confined to Read the Docs. `SPHINX_JOBS` defaults to
`auto`, so local builds and the Buildkite doc build are untouched.
Verified with `make -n`: the default still renders `-j auto`, the
override renders `-j 2`, and because `RTDSPHINXOPTS` and `LINKCHECKOPTS`
derive from the same variable, the override also reaches `linkcheck`,
`rtd-build`, and `rtd-fallback`. That last part matters for when the
incremental cache path in #64277 is re-enabled — the cap will apply
there too without another change.
## Why 2 rather than 3
2 is the value with a measured peak and a clean `oom_kill 0`. 3 would
cost less wall clock and is plausibly enough, but it hasn't been
measured, and at 3 workers the expected headroom lands between the two
figures above, closer to the margin that is already producing
intermittent kills. Given the failure mode is timing-dependent rather
than threshold-dependent, the point of the change is durable headroom
rather than getting just back under a line. If the wall-clock cost
proves painful, 3 is the obvious thing to measure next.
## Follow-up
Read the Docs documents the memory limit as upgradable on Business.
Raising it would let the parallelism come back and undo the wall-clock
cost. That's a separate ask to Read the Docs rather than a change in
this repo, and it's worth making regardless of this PR.
#65631 is the measurement PR that produced the numbers above. It can be
closed once this lands; the `SPHINX_JOBS` plumbing it carried is
included here, and its diagnostic wrapper was always meant to come back
out.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Signed-off-by: Douglas Strodtman <[email protected]>
|
Closing as obsolete. This PR was the temporary diagnostic wrapper to measure builder CPU and peak memory around the RtD Sphinx build at |
…project#65643) ## Summary Read the Docs builds intermittently fail with a bare `EOFError` and no failing document named: ``` File ".../multiprocessing/connection.py", line 399, in _recv raise EOFError EOFError make: *** [Makefile:91: html] Error 2 ``` The kernel OOM-kills one of Sphinx's parallel write workers, and the parent process has nothing better to report than the broken pipe. This caps the worker count on the Read the Docs builder, which is the only builder with a hard memory ceiling. Two changes: - `doc/Makefile` gains `SPHINX_JOBS ?= auto`, feeding `sphinx-build -j`. The default keeps today's behavior for every existing caller. - The `.readthedocs.yaml` html job passes `SPHINX_JOBS=2`. ## The mechanism The builder has 4 CPUs and a cgroup `memory.max` of 7,130,316,800 bytes, about 6.64 GiB, which matches the memory limit Read the Docs documents for Business. `-j auto` forks one write worker per CPU and each worker carries its own copy of the build environment, so the write phase costs memory in proportion to the job count. Measured on the builder, with `memory.events` read immediately after the build: | Job count | `memory.peak` | Headroom under the ceiling | `oom_kill` | Result | |---|---|---|---|---| | `auto` (4) | 6,371,254,272 | ~759 MB | 1 | failed, `EOFError` | | `auto` (4) | 6,503,370,752 | ~627 MB | 0 | passed | | 2 | 5,566,427,136 | ~1,564 MB | 0 | passed | The two `-j auto` rows are the important pair: the run that was killed peaked *lower* than the run that passed. There is no threshold being crossed. The build simply runs about 600 MB under a hard ceiling with four workers allocating independently, and whether a given run survives depends on the timing of individual allocations. That is also why the document Sphinx dies on moves between builds, which is what makes the failure read as a content problem when it isn't. Dropping to 2 workers roughly doubles the headroom, from about 600 MB to about 1.5 GiB. ## Why this is worth doing rather than waiting The parallelism is recent, not long-standing. Read the Docs' own Sphinx invocation adds `-j auto` only for projects carrying the opt-in `BUILD_IN_PARALLEL` feature flag, so RtD was building Ray's docs serially. ray-project#64277 pointed `build.jobs.build.html` at `make -C doc html`, which inherited the Makefile's `-j auto` — a flag that until then only the Buildkite doc build used. ray-project#64599 then made every preview a full clean `-a -E` build. Neither change was wrong on its own; together they put four write workers and a thin memory margin on the one builder that can't absorb them. Some things that this is *not*, all checked: - **Not content growth.** The Sphinx environment went from 4058 documents on a passing build to 4087 on a failing one. 0.7% can't move a build across a ceiling. - **Not dependency drift.** `doc/requirements-doc.lock.txt` is fully hash-pinned and unchanged across the window. - **Not worker overcommit.** Sphinx resolves `-j auto` through `multiprocessing.cpu_count`, which is neither affinity- nor cgroup-aware, so it can in principle fork more workers than the container can run. On this builder `nproc` and `nproc --all` both report 4, so that isn't happening. - **Not host contention.** The ceiling is a per-build cgroup limit, not host pressure, so this isn't other builds crowding the machine. ## Cost Wall clock. A paired run on one builder measured 349 seconds at `-j auto` against 620 seconds at `SPHINX_JOBS=2`, about 78% slower. The `SPHINX_JOBS=2` arm ran with a warm cache, so treat 78% as a lower bound. That cost is confined to Read the Docs. `SPHINX_JOBS` defaults to `auto`, so local builds and the Buildkite doc build are untouched. Verified with `make -n`: the default still renders `-j auto`, the override renders `-j 2`, and because `RTDSPHINXOPTS` and `LINKCHECKOPTS` derive from the same variable, the override also reaches `linkcheck`, `rtd-build`, and `rtd-fallback`. That last part matters for when the incremental cache path in ray-project#64277 is re-enabled — the cap will apply there too without another change. ## Why 2 rather than 3 2 is the value with a measured peak and a clean `oom_kill 0`. 3 would cost less wall clock and is plausibly enough, but it hasn't been measured, and at 3 workers the expected headroom lands between the two figures above, closer to the margin that is already producing intermittent kills. Given the failure mode is timing-dependent rather than threshold-dependent, the point of the change is durable headroom rather than getting just back under a line. If the wall-clock cost proves painful, 3 is the obvious thing to measure next. ## Follow-up Read the Docs documents the memory limit as upgradable on Business. Raising it would let the parallelism come back and undo the wall-clock cost. That's a separate ask to Read the Docs rather than a change in this repo, and it's worth making regardless of this PR. ray-project#65631 is the measurement PR that produced the numbers above. It can be closed once this lands; the `SPHINX_JOBS` plumbing it carried is included here, and its diagnostic wrapper was always meant to come back out. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: Douglas Strodtman <[email protected]>
Summary
Read the Docs builds intermittently fail with a bare
EOFErrorraised frommultiprocessing/connection.py, with no document named and no cause given:doc/Makefilebuilds with-j auto, so Sphinx forks one write worker per CPU. When a worker dies, the parent reports only thatEOFError. This PR wraps the existingmakeinvocation in the.readthedocs.yamlhtml job so the builder's CPU count, cgroup memory ceiling, peak memory, and cgroup OOM counters print around every build.It's a measurement step, not a fix. Nothing about the build changes.
Why this isn't a content problem
master. Every other RtD failure in that window is an ordinaryfail_on_warningtrip.masterWhy measure before capping
-jThe likely mechanism is the kernel OOM-killing a write worker. Lowering
-jis the obvious response, but choosing a value blind would cost wall-clock on every doc build and might buy nothing, since the useful cap depends on how many CPUs the builder actually has. If the builder has two CPUs,-j autois already 2 and a cap isn't the answer at all. The cgroupmemory.eventsOOM counters settle whether an OOM kill is even what's happening.Implementation notes
post_buildjob becausepost_buildis skipped when the build fails, and the failing build is the one worth measuring.rccarriesmake's exit status through to the job's exit, so a real Sphinx failure still fails the build. Verified undersh -ethat the diagnostics run and the non-zero status propagates.|| trueor|| echo, so a missing file or a non-matchinggrepcan't abort the job underset -e.printfwith escape sequences, no backslash escapes, and no shell comments inside the block.sh -nand by parsing the YAML.Follow-up
Once a few builds have reported their numbers, this wrapper comes back out along with whatever the real fix turns out to be.