def testGet(self): ray.init(start_ray_local=True, num_workers=3) for cls in [ Foo, Bar, Baz, Qux, SubQux, Exception, CustomError, Point, NamedTupleExample ]: ray.register_class(cls) # Remote objects should be deallocated when the corresponding ObjectID goes # out of scope, and all results of ray.get called on the ID go out of scope. for val in RAY_TEST_OBJECTS: x = ray.put(val) objectid = x.id xval = ray.get(x) del x, xval self.assertEqual( ray.scheduler_info()["reference_counts"][objectid], -1) # Remote objects that do not contain numpy arrays should be deallocated when # the corresponding ObjectID goes out of scope, even if ray.get has been # called on the ObjectID. for val in [ True, False, None, 1, 1.0, 1L, "hi", u"hi", [1, 2, 3], (1, 2, 3), [(), { (): () }] ]: x = ray.put(val) objectid = x.id xval = ray.get(x) del x self.assertEqual( ray.scheduler_info()["reference_counts"][objectid], -1)
def testObjStore(self): node_ip_address = "127.0.0.1" scheduler_address = ray.services.start_ray_local(num_objstores=2, num_workers=0, worker_path=None) ray.connect(node_ip_address, scheduler_address, mode=ray.SCRIPT_MODE) objstore_addresses = [objstore_info["address"] for objstore_info in ray.scheduler_info()["objstores"]] w1 = ray.worker.Worker() w2 = ray.worker.Worker() ray.reusables._cached_reusables = [] # This is a hack to make the test run. ray.connect(node_ip_address, scheduler_address, objstore_address=objstore_addresses[0], mode=ray.SCRIPT_MODE, worker=w1) ray.reusables._cached_reusables = [] # This is a hack to make the test run. ray.connect(node_ip_address, scheduler_address, objstore_address=objstore_addresses[1], mode=ray.SCRIPT_MODE, worker=w2) for cls in [Foo, Bar, Baz, Qux, SubQux, Exception, CustomError, Point, NamedTupleExample]: ray.register_class(cls) # putting and getting an object shouldn't change it for data in RAY_TEST_OBJECTS: objectid = ray.put(data, w1) result = ray.get(objectid, w1) assert_equal(result, data) # putting an object, shipping it to another worker, and getting it shouldn't change it for data in RAY_TEST_OBJECTS: objectid = ray.put(data, w1) result = ray.get(objectid, w2) assert_equal(result, data) # putting an object, shipping it to another worker, and getting it shouldn't change it for data in RAY_TEST_OBJECTS: objectid = ray.put(data, w2) result = ray.get(objectid, w1) assert_equal(result, data) # This test fails. See https://github.com/ray-project/ray/issues/159. # getting multiple times shouldn't matter # for data in [np.zeros([10, 20]), np.random.normal(size=[45, 25]), np.zeros([10, 20], dtype=np.dtype("float64")), np.zeros([10, 20], dtype=np.dtype("float32")), np.zeros([10, 20], dtype=np.dtype("int64")), np.zeros([10, 20], dtype=np.dtype("int32"))]: # objectid = worker.put(data, w1) # result = worker.get(objectid, w2) # result = worker.get(objectid, w2) # result = worker.get(objectid, w2) # assert_equal(result, data) # Getting a buffer after modifying it before it finishes should return updated buffer objectid = ray.libraylib.get_objectid(w1.handle) buf = ray.libraylib.allocate_buffer(w1.handle, objectid, 100) buf[0][0] = 1 ray.libraylib.finish_buffer(w1.handle, objectid, buf[1], 0) completedbuffer = ray.libraylib.get_buffer(w1.handle, objectid) self.assertEqual(completedbuffer[0][0], 1) # We started multiple drivers manually, so we will disconnect them manually. ray.disconnect(worker=w1) ray.disconnect(worker=w2) ray.worker.cleanup()
def testGet(self): ray.init(start_ray_local=True, num_workers=3) for cls in [Foo, Bar, Baz, Qux, SubQux, Exception, CustomError, Point, NamedTupleExample]: ray.register_class(cls) # Remote objects should be deallocated when the corresponding ObjectID goes # out of scope, and all results of ray.get called on the ID go out of scope. for val in RAY_TEST_OBJECTS: x = ray.put(val) objectid = x.id xval = ray.get(x) del x, xval self.assertEqual(ray.scheduler_info()["reference_counts"][objectid], -1) # Remote objects that do not contain numpy arrays should be deallocated when # the corresponding ObjectID goes out of scope, even if ray.get has been # called on the ObjectID. for val in [True, False, None, 1, 1.0, 1L, "hi", u"hi", [1, 2, 3], (1, 2, 3), [(), {(): ()}]]: x = ray.put(val) objectid = x.id xval = ray.get(x) del x self.assertEqual(ray.scheduler_info()["reference_counts"][objectid], -1)
def check_everything_deallocated(): reference_counts = ray.scheduler_info()["reference_counts"] self.assertEqual(reference_counts, len(reference_counts) * [-1])
def check_not_deallocated(object_ids): reference_counts = ray.scheduler_info()["reference_counts"] for object_id in object_ids: self.assertGreater(reference_counts[object_id.id], 0)
class ReferenceCountingTest(unittest.TestCase): def testDeallocation(self): reload(test_functions) for module in [ra.core, ra.random, ra.linalg, da.core, da.random, da.linalg]: reload(module) ray.init(start_ray_local=True, num_workers=1) ray.register_class(da.DistArray) def check_not_deallocated(object_ids): reference_counts = ray.scheduler_info()["reference_counts"] for object_id in object_ids: self.assertGreater(reference_counts[object_id.id], 0) def check_everything_deallocated(): reference_counts = ray.scheduler_info()["reference_counts"] self.assertEqual(reference_counts, len(reference_counts) * [-1]) z = da.zeros.remote([da.BLOCK_SIZE, 2 * da.BLOCK_SIZE]) time.sleep(0.1) objectid_val = z.id time.sleep(0.1) check_not_deallocated([z]) del z time.sleep(0.1) check_everything_deallocated() x = ra.zeros.remote([10, 10]) y = ra.zeros.remote([10, 10]) z = ra.dot.remote(x, y) objectid_val = x.id time.sleep(0.1) check_not_deallocated([x, y, z]) del x time.sleep(0.1) check_not_deallocated([y, z]) del y time.sleep(0.1) check_not_deallocated([z]) del z time.sleep(0.1) check_everything_deallocated() z = da.zeros.remote([4 * da.BLOCK_SIZE]) time.sleep(0.1) check_not_deallocated(ray.get(z).objectids.tolist()) del z time.sleep(0.1) check_everything_deallocated() ray.worker.cleanup() def testGet(self): ray.init(start_ray_local=True, num_workers=3) for cls in [Foo, Bar, Baz, Qux, SubQux, Exception, CustomError, Point, NamedTupleExample]: ray.register_class(cls) # Remote objects should be deallocated when the corresponding ObjectID goes # out of scope, and all results of ray.get called on the ID go out of scope. for val in RAY_TEST_OBJECTS: x = ray.put(val) objectid = x.id xval = ray.get(x) del x, xval self.assertEqual(ray.scheduler_info()["reference_counts"][objectid], -1) # Remote objects that do not contain numpy arrays should be deallocated when # the corresponding ObjectID goes out of scope, even if ray.get has been # called on the ObjectID. for val in [True, False, None, 1, 1.0, 1L, "hi", u"hi", [1, 2, 3], (1, 2, 3), [(), {(): ()}]]: x = ray.put(val) objectid = x.id xval = ray.get(x) del x self.assertEqual(ray.scheduler_info()["reference_counts"][objectid], -1) # Remote objects that contain numpy arrays should not be deallocated when # the corresponding ObjectID goes out of scope, if ray.get has been called # on the ObjectID and the result of that call is still in scope. for val in [np.zeros(10), [np.zeros(10)], (((np.zeros(10)),),), {(): np.zeros(10)}, [1, 2, 3, np.zeros(1)]]: x = ray.put(val) objectid = x.id xval = ray.get(x) del x self.assertEqual(ray.scheduler_info()["reference_counts"][objectid], 1) # Getting an object multiple times should not be a problem. And the remote # object should not be deallocated until both of the results are out of scope. for val in [np.zeros(10), [np.zeros(10)], (((np.zeros(10)),),), {(): np.zeros(10)}, [1, 2, 3, np.zeros(1)]]: x = ray.put(val) objectid = x.id xval1 = ray.get(x) xval2 = ray.get(x) del xval1 # Make sure we can still access xval2. xval2 del xval2 self.assertEqual(ray.scheduler_info()["reference_counts"][objectid], 1) xval3 = ray.get(x) xval4 = ray.get(x) xval5 = ray.get(x) del x del xval4, xval5 # Make sure we can still access xval3. xval3 self.assertEqual(ray.scheduler_info()["reference_counts"][objectid], 1) del xval3 self.assertEqual(ray.scheduler_info()["reference_counts"][objectid], -1) # Getting an object multiple times and assigning it to the same name should # work. This was a problem in https://github.com/ray-project/ray/issues/159. for val in [np.zeros(10), [np.zeros(10)], (((np.zeros(10)),),), {(): np.zeros(10)}, [1, 2, 3, np.zeros(1)]]: x = ray.put(val) objectid = x.id xval = ray.get(x) xval = ray.get(x) xval = ray.get(x) xval = ray.get(x) self.assertEqual(ray.scheduler_info()["reference_counts"][objectid], 1) del x self.assertEqual(ray.scheduler_info()["reference_counts"][objectid], 1) del xval self.assertEqual(ray.scheduler_info()["reference_counts"][objectid], -1) ray.worker.cleanup()