Skip to content

PoolActor now uses num_cpus=0 to avoid any deadlock - #22048

Merged
pcmoritz merged 6 commits into
ray-project:masterfrom
czgdp1807:deadlock
Feb 8, 2022
Merged

pcmoritz merged 6 commits into
ray-project:masterfrom
czgdp1807:deadlock

Conversation

@czgdp1807

@czgdp1807 czgdp1807 commented Feb 2, 2022 •

Copy link
Copy Markdown
Contributor

Why are these changes needed?

#21488 (comment) :

We discussed this issue in a bit more detail and came to the conclusion that we should set the CPU resource requirement for each actor in the actor pool to 0, to make the Ray Pool compatible/same behavior as the Python multiprocessing pool. Would that work for you @yogeveran ? (very similar to solution 4 mentioned above, but with 0.0 instead of 0.1, so it works in all cases).

Related issue number

Closes #21488

Checks

@czgdp1807 czgdp1807 added the bug Something that is supposed to be working; but isn't label Feb 2, 2022
@czgdp1807

Copy link
Copy Markdown
Contributor Author

cc: @pcmoritz @wuisawesome

@wuisawesome wuisawesome left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we add the repro from #21488 as a test case?

@czgdp1807
czgdp1807 requested a review from wuisawesome February 3, 2022 11:26
with Pool(ray_address="auto") as pool:
return list(pool.map(poolit_a, range(2, 4, 1)))

ray.init(num_cpus=1)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: can we initialize ray with a fixture if possible? Ideally we can use ray_start_shared_local_modes?

@pcmoritz
pcmoritz merged commit 0f2a222 into ray-project:master Feb 8, 2022
@czgdp1807
czgdp1807 deleted the deadlock branch February 8, 2022 10:15
simonsays1980 pushed a commit to simonsays1980/ray that referenced this pull request Feb 27, 2022
ray-project#21488 (comment) :

> We discussed this issue in a bit more detail and came to the conclusion that we should set the CPU resource requirement for each actor in the actor pool to 0, to make the Ray Pool compatible/same behavior as the Python multiprocessing pool. Would that work for you @yogeveran ? (very similar to solution 4 mentioned above, but with 0.0 instead of 0.1, so it works in all cases).
OneSizeFitsQuorum added a commit to OneSizeFitsQuorum/ray that referenced this pull request Jul 23, 2026
Add an opt-in joblib backend that runs each batch as a short-lived Ray
task instead of a long-lived actor, so pending work surfaces CPU demand
to the Ray autoscaler and finished tasks release their CPUs.

The existing "ray" backend keeps a fixed-size pool of num_cpus=0 actors
(set by ray-project#22048) for the whole Parallel call, which surfaces no resource
demand and prevents worker scale-down. The new "ray_tasks" backend
submits num_cpus=1 tasks; Ray's scheduler bounds concurrency to the
available CPUs, pending tasks drive autoscaling, and tasks release
CPUs on completion.

n_jobs is a concurrency cap, not a startup requirement: with M < N
available CPUs and n_jobs=N, M tasks run and N-M stay pending (and drive
autoscaling toward N). n_jobs=-1 keeps joblib's "all cores" convention;
max_n_jobs sets an explicit cap. register_ray(register_tasks=True)
additionally registers "ray_tasks"; the default is unchanged.

Reuses RayBatchedCalls object-store dedup so a shared sklearn dataset is
ray.put once across batches. Talks only to Ray Core APIs; does not call
the Kubernetes API and does not depend on KubeRay.

Documented in doc/source/ray-more-libs/joblib.rst.

Signed-off-by: OneSizeFitsQuorum <[email protected]>
OneSizeFitsQuorum added a commit to OneSizeFitsQuorum/ray that referenced this pull request Jul 29, 2026
Add an opt-in joblib backend that runs each batch as a short-lived Ray
task instead of a long-lived actor, so pending work surfaces CPU demand
to the Ray autoscaler and finished tasks release their CPUs.

The existing "ray" backend keeps a fixed-size pool of num_cpus=0 actors
(set by ray-project#22048) for the whole Parallel call, which surfaces no resource
demand and prevents worker scale-down. The new "ray_tasks" backend
submits num_cpus=1 tasks; Ray's scheduler bounds concurrency to the
available CPUs, pending tasks drive autoscaling, and tasks release
CPUs on completion.

n_jobs is a concurrency cap, not a startup requirement: with M < N
available CPUs and n_jobs=N, M tasks run and N-M stay pending (and drive
autoscaling toward N). n_jobs=-1 keeps joblib's "all cores" convention;
max_n_jobs sets an explicit cap. register_ray(register_tasks=True)
additionally registers "ray_tasks"; the default is unchanged.

Reuses RayBatchedCalls object-store dedup so a shared sklearn dataset is
ray.put once across batches. Talks only to Ray Core APIs; does not call
the Kubernetes API and does not depend on KubeRay.

Documented in doc/source/ray-more-libs/joblib.rst.

Signed-off-by: OneSizeFitsQuorum <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something that is supposed to be working; but isn't

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Core] [Bug] Recursive ray.util.multiprocessing.Pool deadlock

3 participants