mirror of
https://github.com/wassname/ray.git
synced 2026-10-29 13:30:42 +08:00
Add docs for memory quota settings (#5441)
This commit is contained in:
1 parent
fab5ae64c4
commit
28623d2eac
3 files changed
+89
No files matched your search
@@ -0,0 +1 @@
|
||||
<svg version="1.1" viewBox="0.0 0.0 833.1286089238845 319.254593175853" fill="none" stroke="none" stroke-linecap="square" stroke-miterlimit="10" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg"><clipPath id="p.0"><path d="m0 0l833.1286 0l0 319.2546l-833.1286 0l0 -319.2546z" clip-rule="nonzero"/></clipPath><g clip-path="url(#p.0)"><path fill="#000000" fill-opacity="0.0" d="m0 0l833.1286 0l0 319.2546l-833.1286 0z" fill-rule="evenodd"/><path fill="#d9ead3" d="m7.530184 100.46457l89.98425 0l0 78.74016l-89.98425 0z" fill-rule="evenodd"/><path stroke="#000000" stroke-width="1.0" stroke-linejoin="round" stroke-linecap="butt" d="m7.530184 100.46457l89.98425 0l0 78.74016l-89.98425 0z" fill-rule="evenodd"/><path fill="#000000" d="m25.531504 146.75464l5.125 -13.359375l1.9062481 0l5.46875 13.359375l-2.015625 0l-1.546875 -4.046875l-5.593748 0l-1.46875 4.046875l-1.875 0zm3.859375 -5.484375l4.531248 0l-1.40625 -3.703125q-0.6249981 -1.6875 -0.9374981 -2.765625q-0.265625 1.28125 -0.71875 2.546875l-1.46875 3.921875zm16.162321 1.9375l1.609375 0.21875q-0.265625 1.65625 -1.359375 2.609375q-1.078125 0.9375 -2.671875 0.9375q-1.984375 0 -3.1875 -1.296875q-1.203125 -1.296875 -1.203125 -3.71875q0 -1.578125 0.515625 -2.75q0.515625 -1.171875 1.578125 -1.75q1.0625 -0.59375 2.3125 -0.59375q1.578125 0 2.578125 0.796875q1.0 0.796875 1.28125 2.265625l-1.59375 0.234375q-0.234375 -0.96875 -0.8125 -1.453125q-0.578125 -0.5 -1.390625 -0.5q-1.234375 0 -2.015625 0.890625q-0.78125 0.890625 -0.78125 2.8125q0 1.953125 0.75 2.84375q0.75 0.875 1.953125 0.875q0.96875 0 1.609375 -0.59375q0.65625 -0.59375 0.828125 -1.828125zm6.59375 2.078125l0.234375 1.453125q-0.6875 0.140625 -1.234375 0.140625q-0.890625 0 -1.390625 -0.28125q-0.484375 -0.28125 -0.6875 -0.734375q-0.203125 -0.46875 -0.203125 -1.9375l0 -5.578125l-1.203125 0l0 -1.265625l1.203125 0l0 -2.390625l1.625 -0.984375l0 3.375l1.65625 0l0 1.265625l-1.65625 0l0 5.671875q0 0.6875 0.078125 0.890625q0.09375 0.203125 0.28125 0.328125q0.203125 0.109375 0.578125 0.109375q0.265625 0 0.71875 -0.0625zm0.99580383 -3.375q0 -2.6875 1.484375 -3.96875q1.25 -1.078125 3.046875 -1.078125q2.0 0 3.265625 1.3125q1.265625 1.296875 1.265625 3.609375q0 1.859375 -0.5625 2.9375q-0.5625 1.0625 -1.640625 1.65625q-1.0625 0.59375 -2.328125 0.59375q-2.03125 0 -3.28125 -1.296875q-1.25 -1.3125 -1.25 -3.765625zm1.6875 0q0 1.859375 0.796875 2.796875q0.8125 0.921875 2.046875 0.921875q1.21875 0 2.03125 -0.921875q0.8125 -0.9375 0.8125 -2.84375q0 -1.796875 -0.8125 -2.71875q-0.8125 -0.921875 -2.03125 -0.921875q-1.234375 0 -2.046875 0.921875q-0.796875 0.90625 -0.796875 2.765625zm9.281967 4.84375l0 -9.671875l1.46875 0l0 1.46875q0.5625 -1.03125 1.03125 -1.359375q0.484375 -0.328125 1.0625 -0.328125q0.828125 0 1.6875 0.53125l-0.5625 1.515625q-0.609375 -0.359375 -1.203125 -0.359375q-0.546875 0 -0.96875 0.328125q-0.421875 0.328125 -0.609375 0.890625q-0.28125 0.875 -0.28125 1.921875l0 5.0625l-1.625 0zm11.947052 0l-1.640625 0l0 -10.453125q-0.59375 0.5625 -1.5625 1.140625q-0.953125 0.5625 -1.71875 0.84375l0 -1.59375q1.375 -0.640625 2.40625 -1.5625q1.03125 -0.921875 1.453125 -1.78125l1.0625 0l0 13.40625z" fill-rule="nonzero"/><path fill="#d9ead3" d="m97.514435 100.46457l109.79527 0l0 78.74016l-109.79527 0z" fill-rule="evenodd"/><path stroke="#000000" stroke-width="1.0" stroke-linejoin="round" stroke-linecap="butt" d="m97.514435 100.46457l109.79527 0l0 78.74016l-109.79527 0z" fill-rule="evenodd"/><path fill="#000000" d="m125.421265 146.75464l5.125 -13.359375l1.90625 0l5.46875 13.359375l-2.015625 0l-1.546875 -4.046875l-5.59375 0l-1.46875 4.046875l-1.875 0zm3.859375 -5.484375l4.53125 0l-1.40625 -3.703125q-0.625 -1.6875 -0.9375 -2.765625q-0.265625 1.28125 -0.71875 2.546875l-1.46875 3.921875zm16.162323 1.9375l1.609375 0.21875q-0.265625 1.65625 -1.359375 2.609375q-1.078125 0.9375 -2.671875 0.9375q-1.984375 0 -3.1875 -1.296875q-1.203125 -1.296875 -1.203125 -3.71875q0 -1.578125 0.515625 -2.75q0.515625 -1.171875 1.578125 -1.75q1.0625 -0.59375 2.3125 -0.59375q1.578125 0 2.578125 0.796875q1.0 0.796875 1.28125 2.265625l-1.59375 0.234375q-0.234375 -0.96875 -0.8125 -1.453125q-0.578125 -0.5 -1.390625 -0.5q-1.234375 0 -2.015625 0.890625q-0.78125 0.890625 -0.78125 2.8125q0 1.953125 0.75 2.84375q0.75 0.875 1.953125 0.875q0.96875 0 1.609375 -0.59375q0.65625 -0.59375 0.828125 -1.828125zm6.59375 2.078125l0.234375 1.453125q-0.6875 0.140625 -1.234375 0.140625q-0.890625 0 -1.390625 -0.28125q-0.484375 -0.28125 -0.6875 -0.734375q-0.203125 -0.46875 -0.203125 -1.9375l0 -5.578125l-1.203125 0l0 -1.265625l1.203125 0l0 -2.390625l1.625 -0.984375l0 3.375l1.65625 0l0 1.265625l-1.65625 0l0 5.671875q0 0.6875 0.078125 0.890625q0.09375 0.203125 0.28125 0.328125q0.203125 0.109375 0.578125 0.109375q0.265625 0 0.71875 -0.0625zm0.99580383 -3.375q0 -2.6875 1.484375 -3.96875q1.25 -1.078125 3.046875 -1.078125q2.0 0 3.265625 1.3125q1.265625 1.296875 1.265625 3.609375q0 1.859375 -0.5625 2.9375q-0.5625 1.0625 -1.640625 1.65625q-1.0625 0.59375 -2.328125 0.59375q-2.03125 0Line truncated
|
||||
|
After Width: | Height: | Size: 128 KiB |
@@ -168,6 +168,7 @@ The following are good places to discuss Ray.
|
||||
user-profiling.rst
|
||||
inspect.rst
|
||||
configure.rst
|
||||
memory-management.rst
|
||||
advanced.rst
|
||||
troubleshooting.rst
|
||||
package-ref.rst
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
Memory Management
|
||||
=================
|
||||
|
||||
This page describes how memory management works in Ray, and how you can set memory quotas to ensure memory-intensive applications run predictably and reliably.
|
||||
|
||||
Overview
|
||||
--------
|
||||
|
||||
There are several ways that Ray applications use memory:
|
||||
|
||||
.. image:: images/memory.svg
|
||||
|
||||
Ray system memory: this is memory used internally by Ray
|
||||
- **Redis**: memory used for storing task lineage and object metadata. When Redis becomes full, lineage will start to be be LRU evicted, which makes the corresponding objects ineligible for reconstruction on failure.
|
||||
- **Raylet**: memory used by the C++ raylet process running on each node. This cannot be controlled, but is usually quite small.
|
||||
|
||||
Application memory: this is memory used by your application
|
||||
- **Worker heap**: memory used by your application (e.g., in Python code or TensorFlow), best measured as the *resident set size (RSS)* of your application minus its *shared memory usage (SHR)* in commands such as ``top``.
|
||||
- **Object store memory**: memory used when your application creates objects in the objects store via ``ray.put`` and when returning values from remote functions. Objects are LRU evicted when the store is full. There is an object store server running on each node.
|
||||
- **Object store shared memory**: memory used when your application reads objects via ``ray.get``. Note that if an object is already present on the node, this does not cause additional allocations. This allows large objects to be efficiently shared among many actors and tasks.
|
||||
|
||||
By default, Ray will cap the memory used by Redis at ``min(30% of node memory, 10GiB)``, and object store at ``min(10% of node memory, 20GiB)``, leaving half of the remaining memory on the node available for use by worker heap. You can also manually configure this by setting ``redis_max_memory=<bytes>`` and ``object_store_memory=<bytes>`` on Ray init.
|
||||
|
||||
It is important to note that these default Redis and object store limits do not address the following issues:
|
||||
|
||||
* Actor or task heap usage exceeding the remaining available memory on a node.
|
||||
|
||||
* Heavy use of the object store by certain actors or tasks causing objects required by other tasks to be prematurely evicted.
|
||||
|
||||
To avoid these potential sources of instability, you can set *memory quotas* to reserve memory for individual actors and tasks.
|
||||
|
||||
Heap memory quota
|
||||
-----------------
|
||||
|
||||
When Ray starts, it queries the available memory on a node / container not reserved for Redis and the object store or being used by other applications. This is considered "available memory" that actors and tasks can request memory out of. You can also set ``memory=<bytes>`` on Ray init to tell Ray explicitly how much memory is available.
|
||||
|
||||
To tell the Ray scheduler a task or actor requires a certain amount of available memory to run, set the ``memory`` argument. The Ray scheduler will then reserve the specified amount of available memory during scheduling, similar to how it handles CPU and GPU resources:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# reserve 500MiB of available memory to place this task
|
||||
@ray.remote(memory=500 * 1024 * 1024)
|
||||
def some_function(x):
|
||||
pass
|
||||
|
||||
# reserve 2.5GiB of available memory to place this actor
|
||||
@ray.remote(memory=2500 * 1024 * 1024)
|
||||
class SomeActor(object):
|
||||
def __init__(self, a, b):
|
||||
pass
|
||||
|
||||
In the above example, the memory quota is specified statically by the decorator, but you can also set them dynamically at runtime using ``_remote()`` as follows:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# override the memory quota to 100MiB when submitting the task
|
||||
some_function._remote(memory=100 * 1024 * 1024, kwargs={"x": 1})
|
||||
|
||||
# override the memory quota to 1GiB when creating the actor
|
||||
SomeActor._remote(memory=1000 * 1024 * 1024, kwargs={"a": 1, "b": 2})
|
||||
|
||||
**Enforcement**: If an actor exceeds its memory quota, calls to it will throw ``RayOutOfMemoryError`` and it may be killed. Memory quota is currently enforced on a best-effort basis for actors only (but quota is taken into account during scheduling in all cases).
|
||||
|
||||
Object store memory quota
|
||||
-------------------------
|
||||
|
||||
Use ``@ray.remote(object_store_memory=<bytes>)`` to cap the amount of memory an actor can use for ``ray.put`` and method call returns. This gives the actor its own LRU queue within the object store of the given size, both protecting its objects from eviction by other actors and preventing it from using more than the specified quota. This quota protects objects from unfair eviction when certain actors are producing objects at a much higher rate than others.
|
||||
|
||||
Ray takes this resource into account during scheduling, with the caveat that a node will always reserve ~30% of its object store for global shared use.
|
||||
|
||||
For the driver, you can set its object store memory quota with ``driver_object_store_memory``. Setting object store quota is not supported for tasks.
|
||||
|
||||
Object store shared memory
|
||||
--------------------------
|
||||
|
||||
Object store memory is also used to map objects returned by ``ray.get`` calls in shared memory. While an object is mapped in this way (i.e., there is a Python reference to the object), it is pinned and cannot be evicted from the object store. However, ray does not provide quota management for this kind of shared memory usage.
|
||||
|
||||
Summary
|
||||
-------
|
||||
|
||||
You can set memory quotas to ensure your application runs predictably on any Ray cluster configuration. If you're not sure, you can start with a conservative default configuration like the following and see if any limits are hit:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@ray.remote(
|
||||
memory=2000 * 1024 * 1024,
|
||||
object_store_memory=200 * 1024 * 1024)
|
||||
Reference in new issue
Block a user