mirror of
https://github.com/wassname/ray.git
synced 2026-07-14 11:17:54 +08:00
Ref count objects created with ray.put (#5590)
* wip * add weakref option * tune util * test ref * doc * fix tests
This commit is contained in:
@@ -3028,11 +3028,47 @@ def test_shutdown_disconnect_global_state():
|
||||
assert str(e.value).endswith("ray.init has been called.")
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"ray_start_object_store_memory", [150 * 1024 * 1024], indirect=True)
|
||||
def test_put_pins_object(ray_start_object_store_memory):
|
||||
x_id = ray.put("HI")
|
||||
x_copy = ray.ObjectID(x_id.binary())
|
||||
assert ray.get(x_copy) == "HI"
|
||||
|
||||
# x cannot be evicted since x_id pins it
|
||||
for _ in range(10):
|
||||
ray.put(np.zeros(10 * 1024 * 1024))
|
||||
assert ray.get(x_id) == "HI"
|
||||
assert ray.get(x_copy) == "HI"
|
||||
|
||||
# now it can be evicted since x_id pins it but x_copy does not
|
||||
del x_id
|
||||
for _ in range(10):
|
||||
ray.put(np.zeros(10 * 1024 * 1024))
|
||||
with pytest.raises(ray.exceptions.UnreconstructableError):
|
||||
ray.get(x_copy)
|
||||
|
||||
# weakref put
|
||||
y_id = ray.put("HI", weakref=True)
|
||||
for _ in range(10):
|
||||
ray.put(np.zeros(10 * 1024 * 1024))
|
||||
with pytest.raises(ray.exceptions.UnreconstructableError):
|
||||
ray.get(y_id)
|
||||
|
||||
@ray.remote
|
||||
def check_no_buffer_ref(x):
|
||||
assert x[0].get_buffer_ref() is None
|
||||
|
||||
z_id = ray.put("HI")
|
||||
assert z_id.get_buffer_ref() is not None
|
||||
ray.get(check_no_buffer_ref.remote([z_id]))
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"ray_start_object_store_memory", [150 * 1024 * 1024], indirect=True)
|
||||
def test_redis_lru_with_set(ray_start_object_store_memory):
|
||||
x = np.zeros(8 * 10**7, dtype=np.uint8)
|
||||
x_id = ray.put(x)
|
||||
x_id = ray.put(x, weakref=True)
|
||||
|
||||
# Remove the object from the object table to simulate Redis LRU eviction.
|
||||
removed = False
|
||||
|
||||
@@ -50,7 +50,7 @@ class TestMemoryLimits(unittest.TestCase):
|
||||
def testTooLargeAllocation(self):
|
||||
try:
|
||||
ray.init(num_cpus=1, driver_object_store_memory=100 * MB)
|
||||
ray.put(np.zeros(50 * MB, dtype=np.uint8))
|
||||
ray.put(np.zeros(50 * MB, dtype=np.uint8), weakref=True)
|
||||
self.assertRaises(
|
||||
OBJECT_TOO_LARGE,
|
||||
lambda: ray.put(np.zeros(200 * MB, dtype=np.uint8)))
|
||||
@@ -64,7 +64,7 @@ class TestMemoryLimits(unittest.TestCase):
|
||||
num_cpus=1,
|
||||
object_store_memory=300 * MB,
|
||||
driver_object_store_memory=driver_quota)
|
||||
z = ray.put("hi")
|
||||
z = ray.put("hi", weakref=True)
|
||||
a = LightActor._remote(object_store_memory=a_quota)
|
||||
b = GreedyActor._remote(object_store_memory=b_quota)
|
||||
for _ in range(5):
|
||||
|
||||
@@ -19,7 +19,7 @@ class TestUnreconstructableErrors(unittest.TestCase):
|
||||
ray.shutdown()
|
||||
|
||||
def testDriverPutEvictedCannotReconstruct(self):
|
||||
x_id = ray.put(np.zeros(1 * 1024 * 1024))
|
||||
x_id = ray.put(np.zeros(1 * 1024 * 1024), weakref=True)
|
||||
ray.get(x_id)
|
||||
for _ in range(20):
|
||||
ray.put(np.zeros(10 * 1024 * 1024))
|
||||
|
||||
Reference in New Issue
Block a user