Skip to content

Commit 173f2e8

Browse files
zdevitofacebook-github-bot
authored andcommitted
De-future spawning actors (#813)
Summary: Pull Request resolved: #813 This commit switches actor spawning to no longer return a Future. ActorMesh becomes a DeprecatedNotAFuture to keep existing code working. The implementation delays the send part of endpoints until the actor has spawned. I expect this to have some performance impact, which needs to be measured before we land this. However, this implementation is not what we expect to actually use: the ability to spawn actors/return a ref immediately will be made part of the rust runtime where the overhead will be substantially less. ghstack-source-id: 302498028 exported-using-ghexport Reviewed By: mariusae Differential Revision: D79938417 fbshipit-source-id: f2606bc82087d6aff4f31f826cbad80615cc8982
1 parent a8498fb commit 173f2e8

File tree

8 files changed

+226
-131
lines changed

8 files changed

+226
-131
lines changed

hyperactor_mesh/src/comm/multicast.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ pub trait CastInfo {
254254
/// we represent it as the only member of a 0-dimensonal cast shape,
255255
/// which is the same as a singleton.
256256
fn cast_info(&self) -> (usize, Shape);
257+
fn sender(&self) -> &ActorId;
257258
}
258259

259260
impl<A: Actor> CastInfo for Context<'_, A> {
@@ -265,4 +266,9 @@ impl<A: Actor> CastInfo for Context<'_, A> {
265266
_ => panic!("Expected either both rank and shape or neither"),
266267
}
267268
}
269+
fn sender(&self) -> &ActorId {
270+
self.headers()
271+
.get(CAST_ORIGINATING_SENDER)
272+
.expect("has sender header")
273+
}
268274
}

monarch_hyperactor/src/pytokio.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,13 @@ fn send_result(
149149

150150
#[pymethods]
151151
impl PyPythonTask {
152-
fn block_on(&mut self, py: Python<'_>) -> PyResult<PyObject> {
153-
signal_safe_block_on(py, self.take_task()?)?
152+
fn block_on(mut slf: PyRefMut<PyPythonTask>, py: Python<'_>) -> PyResult<PyObject> {
153+
let task = slf.take_task()?;
154+
// mutable references to python objects must be dropped before calling
155+
// signal_safe_block_on. It will release the GIL, and any other thread
156+
// trying to access slf will throw.
157+
drop(slf);
158+
signal_safe_block_on(py, task)?
154159
}
155160

156161
fn spawn(&mut self) -> PyResult<PyShared> {
@@ -293,9 +298,13 @@ impl PyShared {
293298
let task = self.task()?;
294299
Ok(PythonTaskAwaitIterator::new(task.into_py_any(py)?))
295300
}
296-
pub fn block_on(&mut self, py: Python<'_>) -> PyResult<PyObject> {
297-
let mut task = self.task()?;
298-
task.block_on(py)
301+
pub fn block_on(mut slf: PyRefMut<PyShared>, py: Python<'_>) -> PyResult<PyObject> {
302+
let task = slf.task()?.take_task()?;
303+
// mutable references to python objects must be dropped before calling
304+
// signal_safe_block_on. It will release the GIL, and any other thread
305+
// trying to access slf will throw.
306+
drop(slf);
307+
signal_safe_block_on(py, task)?
299308
}
300309
}
301310

0 commit comments

Comments
 (0)