Fix bug in which worker import counters were treated incorrectly. (#28)

* Fix bug in which worker import counters were treated incorrectly.

* Fix bug in which cached functions-to-run were double counted as exports. This also runs the functions-to-run on the driver only after ray.init is called.

* Only define reusable variables locally after ray.init has been called.

* Remove flaky reference counting tests. It's not clear that these tests make sense.

* Make numbuf pip install verbose.

* Export cached reusable variables before cached remote functions.

* Fix bug causing the worker to hang sometimes. This happens when the worker is trying to run a task, but it hasn't imported enough imports to run the task, so it continually acquires and releases a lock while checking if it has enough imports. However, for some reason, the import thread is waiting to acquire the same lock and never does so (or takes a very long time to do so). By dropping the lock before sleeping, this makes it easier for other threads to acquire the lock.

* Acquire locks using 'with' statements.

* Fix possible test failure.

* Try to start Redis multiple times with different random ports if the original attempt failed.

* Fix test in which we redefine a remote function.
This commit is contained in:
Robert Nishihara
2016-11-06 22:24:39 -08:00
committed by Philipp Moritz
parent 1147c4d34b
commit 90f88af902
5 changed files with 97 additions and 123 deletions
+16 -45
View File
@@ -266,7 +266,13 @@ class APITest(unittest.TestCase):
@ray.remote
def f(x):
return x + 10
self.assertEqual(ray.get(f.remote(0)), 10)
while True:
val = ray.get(f.remote(0))
self.assertTrue((val == 10) or (val == 1))
if val == 10:
break
else:
print("Still using old definition of f, trying again.")
# Test that we can close over plain old data.
data = [np.zeros([3, 5]), (1, 2, "a"), [0.0, 1.0, 2L], 2L, {"a": np.zeros(3)}]
@@ -411,13 +417,19 @@ class APITest(unittest.TestCase):
sys.path.append("fake_directory")
ray.worker.global_worker.run_function_on_all_workers(f)
@ray.remote
def get_path():
def get_path1():
return sys.path
self.assertEqual("fake_directory", ray.get(get_path.remote())[-1])
self.assertEqual("fake_directory", ray.get(get_path1.remote())[-1])
def f(worker):
sys.path.pop(-1)
ray.worker.global_worker.run_function_on_all_workers(f)
self.assertTrue("fake_directory" not in ray.get(get_path.remote()))
# Create a second remote function to guarantee that when we call
# get_path2.remote(), the second function to run will have been run on the
# worker.
@ray.remote
def get_path2():
return sys.path
self.assertTrue("fake_directory" not in ray.get(get_path2.remote()))
ray.worker.cleanup()
@@ -483,47 +495,6 @@ class PythonModeTest(unittest.TestCase):
ray.worker.cleanup()
class PythonCExtensionTest(unittest.TestCase):
# def testReferenceCountNone(self):
# ray.init(start_ray_local=True, num_workers=1)
#
# # Make sure that we aren't accidentally messing up Python's reference counts.
# @ray.remote
# def f():
# return sys.getrefcount(None)
# first_count = ray.get(f.remote())
# second_count = ray.get(f.remote())
# self.assertEqual(first_count, second_count)
#
# ray.worker.cleanup()
def testReferenceCountTrue(self):
ray.init(start_ray_local=True, num_workers=1)
# Make sure that we aren't accidentally messing up Python's reference counts.
@ray.remote
def f():
return sys.getrefcount(True)
first_count = ray.get(f.remote())
second_count = ray.get(f.remote())
self.assertEqual(first_count, second_count)
ray.worker.cleanup()
def testReferenceCountFalse(self):
ray.init(start_ray_local=True, num_workers=1)
# Make sure that we aren't accidentally messing up Python's reference counts.
@ray.remote
def f():
return sys.getrefcount(False)
first_count = ray.get(f.remote())
second_count = ray.get(f.remote())
self.assertEqual(first_count, second_count)
ray.worker.cleanup()
class ReusablesTest(unittest.TestCase):
def testReusables(self):