Fix actor garbage collection by breaking cyclic references (#1064)

* Fix bug in wait_for_pid_to_exit, add test for actor deletion.

* Fix actor garbage collection by breaking cyclic references

* Add test for calling actor method immediately after actor creation.

* Fix bug, must dispatch tasks when workers are killed.

* Fix python test

* Fix cyclic reference problem by creating ActorMethod objects on the fly.

* Try simply increasing the time allowed for many_drivers_test.py.
This commit is contained in:
Stephanie Wang
2017-10-05 00:55:33 -07:00
committed by Robert Nishihara
parent 971becc905
commit aebe9f9374
5 changed files with 66 additions and 22 deletions
+36
View File
@@ -5,10 +5,12 @@ from __future__ import print_function
import collections
import random
import numpy as np
import os
import time
import unittest
import ray
import ray.test.test_utils
class ActorAPI(unittest.TestCase):
@@ -279,6 +281,40 @@ class ActorMethods(unittest.TestCase):
ray.worker.cleanup()
def testActorDeletion(self):
ray.init(num_workers=0)
# Make sure that when an actor handles goes out of scope, the actor
# destructor is called.
@ray.remote
class Actor(object):
def getpid(self):
return os.getpid()
a = Actor.remote()
pid = ray.get(a.getpid.remote())
a = None
ray.test.test_utils.wait_for_pid_to_exit(pid)
actors = [Actor.remote() for _ in range(10)]
pids = ray.get([a.getpid.remote() for a in actors])
a = None
actors = None
[ray.test.test_utils.wait_for_pid_to_exit(pid) for pid in pids]
@ray.remote
class Actor(object):
def method(self):
return 1
# Make sure that if we create an actor and call a method on it
# immediately, the actor doesn't get killed before the method is
# called.
self.assertEqual(ray.get(Actor.remote().method.remote()), 1)
ray.worker.cleanup()
def testActorState(self):
ray.init()
@@ -30,10 +30,10 @@ class Actor1(object):
def driver(redis_address, driver_index):
"""The script for driver 0.
"""The script for all drivers.
This driver should create five actors that each use one GPU and some actors
that use no GPUs. After a while, it should exit.
This driver should create five actors that each use one GPU. After a while,
it should exit.
"""
ray.init(redis_address=redis_address)
@@ -44,7 +44,7 @@ def driver(redis_address, driver_index):
for i in range(driver_index - max_concurrent_drivers + 1):
_wait_for_event("DRIVER_{}_DONE".format(i), redis_address)
def try_to_create_actor(actor_class, timeout=100):
def try_to_create_actor(actor_class, timeout=500):
# Try to create an actor, but allow failures while we wait for the
# monitor to release the resources for the removed drivers.
start_time = time.time()