Skip to content

Commit aba8484

Browse files
mariusaefacebook-github-bot
authored andcommitted
add a "direct" variant to ProcIds (#787)
Summary: Pull Request resolved: #787 With this change, we can name proc ids by their channel address. This avoids having to manufacture world ids for bootstrapping purposes. ghstack-source-id: 301740065 exported-using-ghexport Reviewed By: shayne-fletcher, vidhyav Differential Revision: D79761721 fbshipit-source-id: 7a8eb173ee8ccca36e6ec484a857e57bd7e9d58f
1 parent b5ecd8f commit aba8484

File tree

21 files changed

+474
-156
lines changed

21 files changed

+474
-156
lines changed

controller/src/lib.rs

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,11 @@ impl ControllerActor {
175175
) -> Result<(ActorHandle<ProcActor>, ActorRef<ControllerActor>), anyhow::Error> {
176176
let bootstrap = ProcActor::bootstrap(
177177
controller_id.proc_id().clone(),
178-
controller_id.proc_id().world_id().clone(), // REFACTOR(marius): make world_id a parameter of ControllerActor::bootstrap
178+
controller_id
179+
.proc_id()
180+
.world_id()
181+
.expect("multiprocess supports only ranked procs")
182+
.clone(), // REFACTOR(marius): make world_id a parameter of ControllerActor::bootstrap
179183
listen_addr,
180184
bootstrap_addr.clone(),
181185
supervision_update_interval,
@@ -685,7 +689,12 @@ mod tests {
685689
world_size: 1,
686690
comm_actor_ref: comm_handle.bind(),
687691
worker_gang_ref: GangId(
688-
WorldId(proc.proc_id().world_name().to_string()),
692+
WorldId(
693+
proc.proc_id()
694+
.world_name()
695+
.expect("only ranked actors are supported in the controller tests")
696+
.to_string(),
697+
),
689698
"worker".to_string(),
690699
)
691700
.into(),
@@ -869,7 +878,12 @@ mod tests {
869878
world_size: 1,
870879
comm_actor_ref: comm_handle.bind(),
871880
worker_gang_ref: GangId(
872-
WorldId(proc.proc_id().world_name().to_string()),
881+
WorldId(
882+
proc.proc_id()
883+
.world_name()
884+
.expect("only ranked actors are supported in the controller tests")
885+
.to_string(),
886+
),
873887
"worker".to_string(),
874888
)
875889
.into(),
@@ -975,7 +989,12 @@ mod tests {
975989
.await
976990
.unwrap();
977991

978-
let world_id = WorldId(proc.proc_id().world_name().to_string());
992+
let world_id = WorldId(
993+
proc.proc_id()
994+
.world_name()
995+
.expect("only ranked actors are supported in the controller tests")
996+
.to_string(),
997+
);
979998
let controller_handle = proc
980999
.spawn::<ControllerActor>(
9811000
"controller",
@@ -1500,7 +1519,12 @@ mod tests {
15001519
world_size: 1,
15011520
comm_actor_ref: ActorRef::attest(controller_id.proc_id().actor_id("comm", 0)),
15021521
worker_gang_ref: GangId(
1503-
WorldId(proc_id.world_name().to_string()),
1522+
WorldId(
1523+
proc_id
1524+
.world_name()
1525+
.expect("only ranked actors are supported in the controller tests")
1526+
.to_string(),
1527+
),
15041528
"worker".to_string(),
15051529
)
15061530
.into(),
@@ -1591,7 +1615,12 @@ mod tests {
15911615
world_size: 1,
15921616
comm_actor_ref: ActorRef::attest(controller_id.proc_id().actor_id("comm", 0)),
15931617
worker_gang_ref: GangId(
1594-
WorldId(proc_id.world_name().to_string()),
1618+
WorldId(
1619+
proc_id
1620+
.world_name()
1621+
.expect("only ranked actors are supported in the controller tests")
1622+
.to_string(),
1623+
),
15951624
"worker".to_string(),
15961625
)
15971626
.into(),
@@ -1692,7 +1721,12 @@ mod tests {
16921721
world_size: 1,
16931722
comm_actor_ref: ActorRef::attest(controller_id.proc_id().actor_id("comm", 0)),
16941723
worker_gang_ref: GangId(
1695-
WorldId(proc_id.world_name().to_string()),
1724+
WorldId(
1725+
proc_id
1726+
.world_name()
1727+
.expect("only ranked actors are supported in the controller tests")
1728+
.to_string(),
1729+
),
16961730
"worker".to_string(),
16971731
)
16981732
.into(),
@@ -1835,7 +1869,12 @@ mod tests {
18351869
world_size: 1,
18361870
comm_actor_ref: ActorRef::attest(controller_id.proc_id().actor_id("comm", 0)),
18371871
worker_gang_ref: GangId(
1838-
WorldId(proc_id.world_name().to_string()),
1872+
WorldId(
1873+
proc_id
1874+
.world_name()
1875+
.expect("only ranked actors are supported in the controller tests")
1876+
.to_string(),
1877+
),
18391878
"worker".to_string(),
18401879
)
18411880
.into(),

hyper/src/commands/demo.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ impl DemoCommand {
6161

6262
let proc_actor = ProcActor::bootstrap(
6363
proc_id.clone(),
64-
proc_id.0.clone(),
64+
proc_id
65+
.world_id()
66+
.expect("unranked proc not supported")
67+
.clone(),
6568
addr,
6669
system_addr,
6770
Duration::from_secs(5),

hyperactor/src/mailbox.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
//! # use hyperactor::mailbox::Mailbox;
2020
//! # use hyperactor::reference::{ActorId, ProcId, WorldId};
2121
//! # tokio_test::block_on(async {
22-
//! # let proc_id = ProcId(WorldId("world".to_string()), 0);
22+
//! # let proc_id = ProcId::Ranked(WorldId("world".to_string()), 0);
2323
//! # let actor_id = ActorId(proc_id, "actor".to_string(), 0);
2424
//! let mbox = Mailbox::new_detached(actor_id);
2525
//! let (port, mut receiver) = mbox.open_port::<u64>();
@@ -36,7 +36,7 @@
3636
//! # use hyperactor::mailbox::Mailbox;
3737
//! # use hyperactor::reference::{ActorId, ProcId, WorldId};
3838
//! # tokio_test::block_on(async {
39-
//! # let proc_id = ProcId(WorldId("world".to_string()), 0);
39+
//! # let proc_id = ProcId::Ranked(WorldId("world".to_string()), 0);
4040
//! # let actor_id = ActorId(proc_id, "actor".to_string(), 0);
4141
//! let mbox = Mailbox::new_detached(actor_id);
4242
//!
@@ -2517,7 +2517,11 @@ mod tests {
25172517
#[test]
25182518
fn test_error() {
25192519
let err = MailboxError::new(
2520-
ActorId(ProcId(WorldId("myworld".into()), 2), "myactor".into(), 5),
2520+
ActorId(
2521+
ProcId::Ranked(WorldId("myworld".to_string()), 2),
2522+
"myactor".to_string(),
2523+
5,
2524+
),
25212525
MailboxErrorKind::Closed,
25222526
);
25232527
assert_eq!(format!("{}", err), "myworld[2].myactor[5]: mailbox closed");

hyperactor/src/proc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ impl Proc {
376376
pub fn local() -> Self {
377377
// TODO: name these something that is ~ globally unique, e.g., incorporate
378378
// the hostname, some GUID, etc.
379-
let proc_id = ProcId(id!(local), NEXT_LOCAL_RANK.fetch_add(1, Ordering::Relaxed));
379+
let proc_id = ProcId::Ranked(id!(local), NEXT_LOCAL_RANK.fetch_add(1, Ordering::Relaxed));
380380
// TODO: make it so that local procs can talk to each other.
381381
Proc::new(proc_id, BoxedMailboxSender::new(PanickingMailboxSender))
382382
}

0 commit comments

Comments
 (0)