import ray
import numpy as np
ray.init()
@ray.remote
def f():
return np.zeros(10000000)
results = []
for i in range(100):
print(i)
results += ray.get([f.remote() for _ in range(50)])
通常,当对象存储填满时,它会开始驱逐未使用的对象(以最近最少使用的方式)。但是,由于所有对象都是保存在结果列表中的 numpy 数组,它们都还在使用中,而这些 numpy 数组所在的内存实际上在对象存储中,因此它们在对象存储。在这些对象超出范围之前,对象存储无法驱逐它们。问题:如何在不超出单机内存的情况下指定像redis这样的外部对象存储?我不想使用/dev/shm 或/tmp 作为对象存储,因为只有有限的内存可用并且它很快就会填满
最佳答案
从 ray 1.2.0 开始,支持对象溢出以支持核外数据处理。从 1.3+(将在 3 周后发布),此功能将默认开启。
https://docs.ray.io/en/latest/memory-management.html#object-spilling
但是您的示例不适用于此功能。让我在这里解释一下原因。
有两件事你需要知道。
ref = f.remote()
print(ref)
ray.get
在此引用上,现在 python 变量直接访问内存(在 Ray 中,它将在共享内存中,如果对象大小 >= 100KB,则由称为 Plasma 存储的 ray 分布式对象存储管理)。所以,obj = ray.get(ref) # Now, obj is pointing to the shared memory directly.
目前,对象溢出功能支持第 1 种情况的磁盘溢出,但不支持第 2 种情况(如果您想象,支持 2 会更棘手)。所以这里有 2 个解决方案;
ray.init(_plasma_directory="/tmp")
这将允许您使用 tmp
文件夹作为等 ionic 存储(意味着射线对象存储在 tmp 文件系统中)。请注意,当您使用此选项时,您可能会看到性能下降。ray.get
获取所有射线对象, 使用 ray.wait
. import ray
import numpy as np
# Note: You don't need to specify this if you use the latest master.
ray.init(
_system_config={
"automatic_object_spilling_enabled": True,
"object_spilling_config": json.dumps(
{"type": "filesystem", "params": {"directory_path": "/tmp/spill"}},
)
},
)
@ray.remote
def f():
return np.zeros(10000000)
result_refs = []
for i in range(100):
print(i)
result_refs += [f.remote() for _ in range(50)]
while result_refs:
[ready], result_refs = ray.wait(result_refs)
result = ray.get(ready)
关于python - Ray 对象存储使用内核外内存不足。如何配置像 s3 存储桶这样的外部对象存储?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66404582/