Skip to content

[Core] Fix 16GB mac perf issue by limit the plasma store size to 2GB - #21224

Merged
scv119 merged 5 commits into
ray-project:masterfrom
scv119:fix-mac-perf-issue
Jan 24, 2022
Merged

scv119 merged 5 commits into
ray-project:masterfrom
scv119:fix-mac-perf-issue

Conversation

@scv119

@scv119 scv119 commented Dec 21, 2021 •

Copy link
Copy Markdown
Contributor

Mac with 16GB memory has degraded performance when concurrently write to more than 2GB
sized mmaped region. (see #20388 for details)
The workaround here is to limit capacity to 2GB for 16GB Mac by default,
and raising warning if the capacity is overwritten by user.

Related issue number

Checks

@scv119
scv119 requested a review from ericl December 21, 2021 20:22
@scv119 scv119 linked an issue Dec 21, 2021 that may be closed by this pull request
2 tasks done
@scv119

scv119 commented Dec 21, 2021

Copy link
Copy Markdown
Contributor Author

cc @rkooo567 to verify if this fixed the problem

@scv119
scv119 force-pushed the fix-mac-perf-issue branch from 69bb393 to d4522a6 Compare December 21, 2021 20:29
Comment thread python/ray/_private/resource_spec.py Outdated

@ericl ericl Dec 21, 2021 •

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.

Shall we just do it for all macs? For 8GB, the detected memory will be about 2GB anyways, so I think this would simplify the logic and prevent edge cases.

Comment thread python/ray/_private/resource_spec.py Outdated

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.

Could we make this an error, guarded by RAY_OBJECT_STORE_ALLOW_BAD_OSX_CONFIG?

I.e., mirroring this other error:

                raise ValueError(
                    "The configured object store size ({} GB) exceeds "
                    "/dev/shm size ({} GB). This will harm performance. "
                    "Consider deleting files in /dev/shm or increasing its "
                    "size with "
                    "--shm-size in Docker. To ignore this warning, "
                    "set RAY_OBJECT_STORE_ALLOW_SLOW_STORAGE=1.".format(
                        object_store_memory / 1e9, shm_avail / 1e9))

@rkooo567

Copy link
Copy Markdown
Contributor

@scv119 will run the workload again on my local machine

@scv119
scv119 force-pushed the fix-mac-perf-issue branch from d4522a6 to 017499a Compare December 30, 2021 20:01
@rkooo567

rkooo567 commented Jan 3, 2022

Copy link
Copy Markdown
Contributor

Seems like many tests fail now. Is it okay to run this now?

@scv119

scv119 commented Jan 3, 2022

Copy link
Copy Markdown
Contributor Author

I think so; seems master has some issues..

@scv119
scv119 force-pushed the fix-mac-perf-issue branch 2 times, most recently from 6073295 to 669479f Compare January 9, 2022 22:46
@scv119

scv119 commented Jan 11, 2022

Copy link
Copy Markdown
Contributor Author

@rkooo567 I believe it's the time to try this out

@rkooo567

Copy link
Copy Markdown
Contributor

doing it rn

@rkooo567

rkooo567 commented Jan 13, 2022 •

Copy link
Copy Markdown
Contributor
(dashboard) sangbincho@SangBins-MacBook-Pro-16-inch-2019 spillissuemac % python a.py 
start
2022-01-12 22:53:00,494	INFO services.py:1384 -- View the Ray dashboard at http://127.0.0.1:8265
2022-01-12 22:53:00,498	INFO services.py:1891 -- object_store_memory is not verified when plasma_directory is set.
Traceback (most recent call last):
  File "a.py", line 7, in <module>
    ray.init(object_store_memory=8e9, _plasma_directory="/tmp")
  File "/Users/sangbincho/work/ray/python/ray/_private/client_mode_hook.py", line 105, in wrapper
    return func(*args, **kwargs)
  File "/Users/sangbincho/work/ray/python/ray/worker.py", line 923, in init
    ray_params=ray_params)
  File "/Users/sangbincho/work/ray/python/ray/node.py", line 256, in __init__
    self.start_ray_processes()
  File "/Users/sangbincho/work/ray/python/ray/node.py", line 1096, in start_ray_processes
    huge_pages=self._ray_params.huge_pages
  File "/Users/sangbincho/work/ray/python/ray/_private/services.py", line 1924, in determine_plasma_store_config
    ray_constants.MAC_DEGRADED_PERF_MMAP_SIZE_LIMIT / 2**30))
ValueError: The configured object store size (7.451GiB) exceeds the optimal size on Mac (2.0GiB). This will harm performance! There is a known issue where Ray's performance degrades with object store size greater than 2.0GB on a Mac.To reduce the object store capacity, specify`object_store_memory` when calling ray.init() or ray start.To ignore this warning, set RAY_OBJECT_STORE_ALLOW_MAC_LARGE_SIZE=1.
zsh: terminated  python a.py
(dashboard) sangbincho@SangBins-MacBook-Pro-16-inch-2019 spillissuemac % vi a.py    
(dashboard) sangbincho@SangBins-MacBook-Pro-16-inch-2019 spillissuemac % python a.py
start
2022-01-12 22:53:24,970	INFO services.py:1384 -- View the Ray dashboard at http://127.0.0.1:8265
2022-01-12 22:53:24,974	INFO services.py:1891 -- object_store_memory is not verified when plasma_directory is set.
done 4.481249094009399
4.894397020339966
(f pid=17453) ObjectRef(623b26bdd75b28e9ffffffffffffffffffffffff0100000002000000)
(f pid=17453) took  0.7948019504547119
(f pid=17451) ObjectRef(a67dc375e60ddd1affffffffffffffffffffffff0100000002000000)
(f pid=17451) took  0.7841081619262695
(f pid=17445) ObjectRef(480a853c2c4c6f27ffffffffffffffffffffffff0100000002000000)
(f pid=17445) took  0.9162602424621582
(f pid=17453) ObjectRef(63964fa4841d4a2effffffffffffffffffffffff0100000002000000)
(f pid=17453) took  0.6102640628814697
(f pid=17451) ObjectRef(69a6825d641b4613ffffffffffffffffffffffff0100000002000000)
(f pid=17451) took  0.750230073928833
(f pid=17445) ObjectRef(ee4e90da584ab0ebffffffffffffffffffffffff0100000002000000)
(f pid=17445) took  0.6338438987731934
(f pid=17454) ObjectRef(4ee449587774c1f0ffffffffffffffffffffffff0100000002000000)
(f pid=17454) took  0.6133909225463867
2.933835983276367
(f pid=17450) ObjectRef(32cccd03c567a254ffffffffffffffffffffffff0100000002000000)
(f pid=17450) took  0.4958009719848633

This seems fast when I set the memory to 2GB & no memory specification

@rkooo567

rkooo567 commented Jan 13, 2022 •

Copy link
Copy Markdown
Contributor
(dashboard) sangbincho@SangBins-MacBook-Pro-16-inch-2019 spillissuemac % RAY_OBJECT_STORE_ALLOW_MAC_LARGE_SIZE=1 python a.py
start
2022-01-12 22:54:41,903	INFO services.py:1384 -- View the Ray dashboard at http://127.0.0.1:8265
2022-01-12 22:54:41,908	INFO services.py:1891 -- object_store_memory is not verified when plasma_directory is set.
done 4.052382230758667
3.6435251235961914
(f pid=17665) ObjectRef(63964fa4841d4a2effffffffffffffffffffffff0100000002000000)
(f pid=17665) took  49.67311930656433

8GB

@rkooo567

rkooo567 commented Jan 13, 2022 •

Copy link
Copy Markdown
Contributor

@scv119 should we experiment with your laptop to see when it slows down? Or are we just always allowing 2GB at max?

@rkooo567 rkooo567 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.

LGTM.

#21224 (comment) -> this is the only question I have!

dstrodtman added a commit that referenced this pull request Oct 7, 2026
…66791)

## Why are these changes needed?

The Ray Core style-pass stack, #66642 through #66677, flagged
pre-existing claims that looked inconsistent with the source, and kept
them as written. This PR corrects the ones that current source settles.
Each one either lags a deliberate code change or never matched the code.
None traces to a code regression, so for each one the source describes
the intended behavior.

It's stacked on #66790, the mechanical fixes for the same pages, which
is stacked on #66677.

**For Core reviewers:** these corrections change what the docs say, so
please confirm them. Each item cites the source it rests on, at master
`5cf675f`, and the history of the disagreement. Items marked **confirm**
carry a specific point to check.

### Top-level pages

- `head-node-memory-management.md`: the note claimed KubeRay ignores
memory and CPU requests, but KubeRay uses the CPU request when the CPU
limit is absent (`ray-operator/controllers/ray/common/pod.go`). Per
review, the note now states the general rule without naming resource
types: set requests equal to limits, because KubeRay configures Ray's
logical resources from the limits. The note was wrong from the start, in
#58695.
- `handling-dependencies.md`, the paths and URIs rules: a local path can
also be a file, such as a local archive for `working_dir` or a `.whl`
for `py_modules`, as the page's own API reference says. Remote URIs can
be `.zip`, `.tar.gz`, `.tgz`, or `.tar.xz` archives, per
`python/ray/_private/runtime_env/packaging.py`. Remote tar archives
arrived in #62813, first released in 2.56.0, and #65742. **Confirm**
that the single top-level directory rule applies to tar archives too.
- `handling-dependencies.md`: `image_uri` is a `str`
(`python/ray/runtime_env/runtime_env.py`), not a `dict`. #49752 carried
`(dict)` over from the `container` field.
- `ray-generator.md`: `ObjectRefGenerator` isn't a Python generator and
doesn't fully implement the generator interface: `send`, `throw`, and
`close` raise `NotImplementedError`
(`python/ray/_private/object_ref_generator.py`). The sentence now says
only that you can iterate with a `for` loop.
- `tips-for-first-time.md`: the first value `ray.wait()` returns is a
list of ready refs (`python/ray/_private/worker.py`), as the page's API
table and sample, which indexes `done_id[0]`, already show.
- `resource-isolation-with-cgroupv2.md`: the default minimum reserved
system memory is `500 * (1024**2)`
(`python/ray/_private/ray_constants.py`). The listing wrote `0.5 *
1024**3`, which is 512 MiB, beside a `#500MiB` comment.
- `type-hint.md`: the `ActorProxy` handle sample called `func.remote()`
on an undecorated function and omitted its `actor` argument and its
imports. It now decorates `func`, passes the handle, and imports what it
uses. **Confirm** that passing the handle into a task is the intended
illustration.

### Tasks, actors, and objects

- `tasks/nested-tasks.md`: Ray pickles and exports a remote function on
its first `.remote()` call, in `RemoteFunction._remote()`
(`python/ray/remote_function.py`), not at definition. Export has been
lazy since before the note was written, in Ray 0.7. **Confirm** that
cloudpickle captures `f` at that point, or say if the note should go.
- `actors/concurrency-group-api.md`: the Java sample set both groups to
a maximum concurrency of 1, while the prose and the Python sample say 2
for `io` and 4 for `compute`. The Java sample now matches. This is a
code change in an untested `java` block.
- `objects/serialization.md`: drops "Most Python distributions default
to Pickle protocol 3". No supported Python does: `python/setup.py`
requires 3.10 or later, where the default is 4 or 5. The sentence went
stale when Ray dropped Python 3.7 in 2.9.0.
- `actors/index.md`: `ray.cancel` defaults `recursive` to `True`
(`python/ray/_private/worker.py`), and always has, so recursive
cancellation is the default and `recursive=False` opts out.
- `tasks/dynamic-generators.md`: adds the caveat from the page's own
sample, `doc_code/generator.py` (`__dynamic_generator_pass_start__`),
which says to avoid passing the generator because the extra `ray.get`
blocks the driver.

### Design patterns

- `patterns/ray-get-too-many-objects.md`: fetching too many objects "can
lead to" failure rather than "leads to" it, matching the next paragraph
and the sample's "if NUM_TASKS is large enough".
- `patterns/out-of-band-object-ref-serialization.md`: the pin lasts for
the lifetime of the worker that serialized the ref.
`python/ray/_private/serialization.py` adds a never-removed local
reference in the serializing process. The object is also gone if its
owner dies. **Confirm** the borrower case: when the serializer isn't the
owner, the owner cleans up a failed borrower's references
(`src/ray/core_worker/reference_counter.cc`). An automated review on
#66667 said the deserializing worker holds the pin instead. The source
comment at the pin site says the serializing worker does.

### Fault tolerance and scheduling

- `scheduling/index.md`: `k` is the larger of
`RAY_scheduler_top_k_absolute` and the rounded-down product of the node
count and `RAY_scheduler_top_k_fraction`
(`src/ray/raylet/scheduling/policy/hybrid_scheduling_policy.cc`). With
the defaults, that's 20% of nodes, rounded down, and at least 1.
- `scheduling/placement-group.md`: PACK is a soft policy, as the same
paragraph says, so Ray "tries to" put both bundles on one node. Only
STRICT_PACK requires it.
- `scheduling/ray-oom-prevention.md`: the policy ranks workers, and
`LeaseSpecification::IsRetriable()`
(`src/ray/common/lease/lease_spec.cc`) treats any nonzero `max_retries`
or `max_restarts`, including `-1`, as retryable.
- `fault-tolerance/objects.md`: `RAY_TASK_MAX_RETRIES` overrides only
the default `max_retries` for remote functions, when the option isn't
set (`python/ray/remote_function.py`). Tasks that set `max_retries`, and
actor tasks with `max_task_retries`, still reconstruct. The "entirely"
wording came in #27573, after #25189 introduced the variable as a
default override.
- `fault-tolerance/actors.md`: `ActorUnavailableError` retries apply to
any nonzero `max_task_retries`. `-1` retries without limit
(`src/ray/core_worker/task_manager.cc`, and the `max_task_retries`
docstring in `python/ray/actor.py`), as L21 of the same page already
counts it.
- `fault-tolerance/index.md`: a task pinned by a node-specific custom
resource "can't be retried on other nodes", the wording of the example's
own comment in `doc_code/fault_tolerance_tips.py`, rather than "won't be
retried".
- `scheduling/resources.md`: the whole-number rule above 1 is enforced
for GPUs (`python/ray/includes/task_options_utils.pxi`), while
`neuron_cores` rejects any fractional value
(`python/ray/_private/accelerators/neuron.py`) and TPU accepts only 1,
2, 4, or 8 (`python/ray/_private/accelerators/tpu.py`).
- `scheduling/memory-management.md`: on macOS, Ray caps the default
object store at 2 GiB (`MAC_DEGRADED_PERF_MMAP_SIZE_LIMIT` in
`python/ray/_private/ray_constants.py`) and raises an error for a larger
requested size unless `RAY_ENABLE_MAC_LARGE_OBJECT_STORE=1`
(`python/ray/_private/services.py`). The cap arrived in #21224.
- `scheduling/placement-group.md`: no code reads `NVIDIA_GPU_CLIQUE`.
The variable supplies the value of the `ray.io/gpu-domain` label, which
is what the feature acts on, as the example below the sentence shows.

### Compiled Graph, Ray Direct Transport, and internals

- `direct-transport/index.md`: both the Gloo and NCCL examples call
`create_collective_group`, so the difference worth listing is
`backend="nccl"` against `backend="torch_gloo"`
(`doc_code/direct_transport_gloo.py` and `direct_transport_nccl.py`).
- `internals/task-lifecycle.md`: for a normal task, the executor's
raylet pulls remote arguments before it grants the lease
(`src/ray/raylet/local_lease_manager.cc`,
`lease_dependency_manager.cc`), as a later step on the same page says.
The executor reads them from the local store.
- `internals/port-service-discovery.md`: the raylet spawns worker
processes, and the core worker inside each one is a C++ library. #66677
restores the original wording, and this states it precisely.
- `internals/object-spilling.md`:
- Spill selection isn't LRU. `TryToSpillObjects` walks
`pinned_objects_`, an unordered `absl::flat_hash_map`
(`src/ray/raylet/local_object_manager.h`). LRU is the Plasma eviction
policy for secondary copies, which the page covers separately.
- Proactive spilling starts when the fraction of primary bytes is at
least the threshold, `>=` in `src/ray/raylet/node_manager.cc`, as the
page's trigger table says.
- `object_spilling_threshold` is a fraction of object store capacity,
the configured size, not of available memory (`node_manager.cc`,
`ObjectManager::GetMemoryCapacity()`).
- `max_io_workers` limits each IO worker type separately
(`TryStartIOWorkers` in `src/ray/raylet/worker_pool.cc`), as the worker
pool section of the page already says.
- `internals/metric-exporter.md`: C++ metrics register in their
`ray::stats` constructors when OpenTelemetry is on
(`src/ray/stats/metric.h`), not lazily on first use. Recording an
unregistered name fails a `RAY_CHECK`
(`src/ray/observability/open_telemetry_metric_recorder.cc`). "Lazy
registration" becomes "Idempotent registration", which is what that
bullet describes.

## Related issue number

None. Not a duplicate: I searched open PRs touching `doc/source/core/`
and `doc/source/ray-core/`. Open PRs editing these pages are this stack,
#66464 (Compiled Graph deprecation, on lines this PR doesn't touch), and
#66550 (label selector operators, on lines this PR doesn't touch).

Questions from the style pass that need a Core decision rather than a
source check aren't in this PR. Examples are the `DAGNode.execute()`
deprecation framing, the DEFAULT scheduling strategy's locality wording,
the official KubeRay support scope for GCS fault tolerance, and the Ray
event exporter baseline. They're tracked separately for Core
engineering.

## Checks

- Docs-only: every change is in a `.md` file under `doc/source/core/`,
so no library tests run. The two sample edits, in `type-hint.md` and
`concurrency-group-api.md`, are untested `python` and `java` blocks.
- Every cited claim was re-checked on master `5cf675f`, and the
disagreement's history was traced through release tags to rule out a
code regression.
- `vale` on the 26 changed files from the repo root: four alerts removed
and one added, `Google.Parens` on `image_uri (str)`, which matches the
field-type format of its sibling entries.
- `codespell` on the changed files: clean.
- `doc/.claude/skills/ray-soft-wrap/scripts/softwrap.py --check` on the
changed files: clean.
- `pre-commit`: passed.
- Full `-W` doc build: relying on the Read the Docs preview.

AI assistance (Claude Code) was used to research and draft these edits.
Draft until the submitter has reviewed every changed line and a Core
reviewer has confirmed the claims.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Douglas Strodtman <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

[Bug] modin-on-ray's unwrap_partitions is 100x slower on Mac than on Windows

3 participants