Prototype named actors.#2129
Prototype named actors.#2129robertnishihara merged 6 commits intoray-project:masterfrom heyucongtom:master
Conversation
robertnishihara
left a comment
There was a problem hiding this comment.
This looks great! Please make sure the linting passes.
| # Test getting f | ||
| f2 = ray.experimental.get_actor("f1") | ||
| self.assertEqual(f1._actor_id, f2._actor_id) | ||
|
|
There was a problem hiding this comment.
Let's modify the actor to be something like
def method(self):
self.x += 1
return self.x
so that here we can do
self.assertEqual(ray.get(f1.method.remote(), 1)
self.assertEqual(ray.get(f2.method.remote(), 2)
self.assertEqual(ray.get(f1.method.remote(), 3)
self.assertEqual(ray.get(f2.method.remote(), 4)
test/actor_test.py
Outdated
|
|
||
| # Test getting an unexist actor | ||
| with self.assertRaises(AssertionError): | ||
| err = ray.experimental.get_actor("unexisted") |
There was a problem hiding this comment.
unexisted -> nonexistent
test/actor_test.py
Outdated
| # we should also test this from a different driver. | ||
| ray.get(new_f.method.remote()) | ||
|
|
||
| def testRegisterAndGetActorHandle(self): |
There was a problem hiding this comment.
can we change this to testRegisterAndGetNamedActors? It'll be easier to find by searching
| def _calculate_key_(name): | ||
| return b"Actor:" + str.encode(name) | ||
|
|
||
| def get_actor(name): |
There was a problem hiding this comment.
Please add docstrings for these methods with the format used e.g., in
Lines 2443 to 2458 in 4584193
| assert not is_existed, \ | ||
| "Error: the actor with name={} already exists".format(name) | ||
| pickled_state = pickle.dumps(actor_handle) | ||
| worker.redis_client.hmset(actor_hash, {name: pickled_state}) |
There was a problem hiding this comment.
There is a race condition with this approach. It's possible that another worker could add publish a named actor with the same name between the calls to hexists and hmset. You can avoid this with hsetnx. See https://redis.io/commands/hsetnx.
| from __future__ import absolute_import | ||
| from __future__ import division | ||
| from __future__ import print_function | ||
|
|
There was a problem hiding this comment.
Let's reserve assertions for checking things that should never actually happen. The errors (in both register_actor and get_actor) can happen if the user passes in the wrong values, so we should raise some sort of exception
| def register_actor(name, actor_handle): | ||
| worker = ray.worker.get_global_worker() | ||
| actor_hash = _calculate_key_(name) | ||
| assert type(actor_handle) == ray.actor.ActorHandle, \ |
There was a problem hiding this comment.
should raise TypeError
| assert type(actor_handle) == ray.actor.ActorHandle, \ | ||
| "Error: you could only store named-actors." | ||
| is_existed = worker.redis_client.hexists(actor_hash, name) | ||
| assert not is_existed, \ |
There was a problem hiding this comment.
should raise ValueError
| def get_actor(name): | ||
| worker = ray.worker.get_global_worker() | ||
| actor_hash = _calculate_key_(name) | ||
| pickled_state = worker.redis_client.hmget(actor_hash, name) |
There was a problem hiding this comment.
You can just use hget and then remove the assertion below.
| pickled_state = worker.redis_client.hmget(actor_hash, name) | ||
| assert len(pickled_state) == 1, \ | ||
| "Error: Multiple actors under this name." | ||
| assert pickled_state[0] is not None, \ |
There was a problem hiding this comment.
should raise ValueError
|
To do linting, you can do (from also |
python/ray/experimental/__init__.py
Outdated
| _flush_finished_tasks_unsafe_shard, _flush_evicted_objects_unsafe_shard) | ||
| from .named_actors import ( | ||
| get_actor, register_actor | ||
| ) |
There was a problem hiding this comment.
looks like this can all fit on one line without the parentheses
|
Test FAILed. |
…an actorhandle created by pickling.
| "actor_driver_id": self._ray_actor_driver_id.id(), | ||
| "previous_actor_handle_id": self._ray_actor_handle_id.id(), | ||
| "previous_actor_handle_id": self._ray_actor_handle_id.id() | ||
| if self._ray_actor_handle_id else None, |
There was a problem hiding this comment.
Why is this change needed?
There was a problem hiding this comment.
Hmm.. ok I see that the test failures without it.
robertnishihara
left a comment
There was a problem hiding this comment.
Thanks! I pushed some stylistic changes. I'll merge this once the tests pass.
|
Test PASSed. |
|
Test PASSed. |
|
Test PASSed. |
|
Test PASSed. |
|
One thing I noticed is that calling |
|
I just came across this bug thread earlier today. Would take a look at it
later.
…On Thu, May 24, 2018 at 12:40 AM Robert Nishihara ***@***.***> wrote:
One thing I noticed is that calling get_actor twice on the same name will
cause problems (once you try to use the actor). This is probably the same
issue as #2115 <#2115>.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#2129 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AGbH8bpCJ3UOImrfIXH-TVnTKyaYIwWIks5t1mPVgaJpZM4ULH2Z>
.
|
* master: Prototype named actors. (ray-project#2129) Update arrow to latest master (ray-project#2100) [DataFrame] Speed up dtypes (ray-project#2118) do not fetch from dead Plasma Manager (ray-project#2116) [DataFrame] Refactor GroupBy Methods and Implement Reindex (ray-project#2101) Initial Support for Airspeed Velocity (ray-project#2113) Use automatic memory management in Redis modules. (ray-project#1797) [DataFrame] Test bugfixes (ray-project#2111) [DataFrame] Update initializations of IndexMetadata which use outdated APIs (ray-project#2103)
* fix-a3c-torch: Prototype named actors. (ray-project#2129) Update arrow to latest master (ray-project#2100) [DataFrame] Speed up dtypes (ray-project#2118) do not fetch from dead Plasma Manager (ray-project#2116)
What do these changes do?
Since it's a total re-factorization, I feel like it may be cleaner to open up a new commit tree for the modification. It refer to the same issue as discussed in the pull-request #2120. (Please feel free to close that one.)
This commit deal with:
Related issue number
#1424 #2120