Skip to content

Commit 20c2603

Browse files
committed
fix(hydro_deploy): only instantiate Localhost once
Fixes #841
1 parent 5f2789a commit 20c2603

File tree

8 files changed

+18
-23
lines changed

8 files changed

+18
-23
lines changed

docs/docs/hydroflow_plus/quickstart/clusters.mdx

+2-3
Original file line numberDiff line numberDiff line change
@@ -95,23 +95,22 @@ use hydroflow_plus_cli_integration::{DeployProcessSpec, DeployClusterSpec};
9595
#[tokio::main]
9696
async fn main() {
9797
let mut deployment = Deployment::new();
98-
let localhost = deployment.Localhost();
9998
let profile = "dev";
10099

101100
let builder = hydroflow_plus::FlowBuilder::new();
102101
let (leader, workers) = flow::broadcast::broadcast(&builder);
103102

104103
flow.with_default_optimize()
105104
.with_process(&leader, DeployProcessSpec::new({
106-
HydroflowCrate::new(".", localhost.clone())
105+
HydroflowCrate::new(".", deployment.Localhost())
107106
.bin("broadcast")
108107
.profile(profile)
109108
.display_name("leader")
110109
}))
111110
.with_cluster(&workers, DeployClusterSpec::new({
112111
(0..2)
113112
.map(|idx| {
114-
HydroflowCrate::new(".", localhost.clone())
113+
HydroflowCrate::new(".", deployment.Localhost())
115114
.bin("broadcast")
116115
.profile(profile)
117116
.display_name(format!("worker/{}", idx))

hydro_deploy/core/src/deployment.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,22 @@ pub struct Deployment {
1818
pub hosts: Vec<Weak<dyn Host>>,
1919
pub services: Vec<Weak<RwLock<dyn Service>>>,
2020
pub resource_pool: ResourcePool,
21+
localhost_host: Option<Arc<LocalhostHost>>,
2122
last_resource_result: Option<Arc<ResourceResult>>,
2223
next_host_id: usize,
2324
next_service_id: usize,
2425
}
2526

2627
impl Deployment {
2728
pub fn new() -> Self {
28-
Self::default()
29+
let mut ret = Self::default();
30+
ret.localhost_host = Some(ret.add_host(LocalhostHost::new));
31+
ret
2932
}
3033

3134
#[allow(non_snake_case)]
32-
pub fn Localhost(&mut self) -> Arc<LocalhostHost> {
33-
self.add_host(LocalhostHost::new)
35+
pub fn Localhost(&self) -> Arc<LocalhostHost> {
36+
self.localhost_host.clone().unwrap()
3437
}
3538

3639
#[allow(non_snake_case)]

hydro_deploy/core/src/hydroflow_crate/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,8 @@ mod tests {
143143
async fn test_crate_panic() {
144144
let mut deployment = deployment::Deployment::new();
145145

146-
let localhost = deployment.Localhost();
147-
148146
let service = deployment.add_service(
149-
HydroflowCrate::new("../hydro_cli_examples", localhost.clone())
147+
HydroflowCrate::new("../hydro_cli_examples", deployment.Localhost())
150148
.example("panic_program")
151149
.profile("dev"),
152150
);

hydroflow_plus_test/src/cluster/many_to_many.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ mod tests {
3333
#[tokio::test]
3434
async fn many_to_many() {
3535
let mut deployment = Deployment::new();
36-
let localhost = deployment.Localhost();
3736

3837
let builder = hydroflow_plus::FlowBuilder::new();
3938
let cluster = super::many_to_many(&builder);
@@ -47,7 +46,7 @@ mod tests {
4746
DeployClusterSpec::new({
4847
(0..2)
4948
.map(|_| {
50-
HydroflowCrate::new(".", localhost.clone())
49+
HydroflowCrate::new(".", deployment.Localhost())
5150
.bin("many_to_many")
5251
.profile("dev")
5352
})

hydroflow_plus_test/src/cluster/simple_cluster.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ mod tests {
5050
#[tokio::test]
5151
async fn simple_cluster() {
5252
let mut deployment = Deployment::new();
53-
let localhost = deployment.Localhost();
5453

5554
let builder = hydroflow_plus::FlowBuilder::new();
5655
let (node, cluster) = super::simple_cluster(&builder);
@@ -62,7 +61,7 @@ mod tests {
6261
.with_process(
6362
&node,
6463
DeployProcessSpec::new({
65-
HydroflowCrate::new(".", localhost.clone())
64+
HydroflowCrate::new(".", deployment.Localhost())
6665
.bin("simple_cluster")
6766
.profile("dev")
6867
}),
@@ -72,7 +71,7 @@ mod tests {
7271
DeployClusterSpec::new({
7372
(0..2)
7473
.map(|_| {
75-
HydroflowCrate::new(".", localhost.clone())
74+
HydroflowCrate::new(".", deployment.Localhost())
7675
.bin("simple_cluster")
7776
.profile("dev")
7877
})

hydroflow_plus_test/src/distributed/first_ten.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ mod tests {
4646
#[tokio::test]
4747
async fn first_ten_distributed() {
4848
let mut deployment = Deployment::new();
49-
let localhost = deployment.Localhost();
5049

5150
let builder = hydroflow_plus::FlowBuilder::new();
5251
let (first_node, second_node) = super::first_ten_distributed(&builder);
@@ -60,15 +59,15 @@ mod tests {
6059
.with_process(
6160
&first_node,
6261
DeployProcessSpec::new({
63-
HydroflowCrate::new(".", localhost.clone())
62+
HydroflowCrate::new(".", deployment.Localhost())
6463
.bin("first_ten_distributed")
6564
.profile("dev")
6665
}),
6766
)
6867
.with_process(
6968
&second_node,
7069
DeployProcessSpec::new({
71-
HydroflowCrate::new(".", localhost.clone())
70+
HydroflowCrate::new(".", deployment.Localhost())
7271
.bin("first_ten_distributed")
7372
.profile("dev")
7473
}),

template/hydroflow_plus/flow/examples/first_ten_distributed.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use hydroflow_plus_cli_integration::DeployProcessSpec;
44
#[tokio::main]
55
async fn main() {
66
let mut deployment = Deployment::new();
7-
let localhost = deployment.Localhost();
87

98
let flow = hydroflow_plus::FlowBuilder::new();
109
let (p1, p2) = flow::first_ten_distributed::first_ten_distributed(&flow);
@@ -14,15 +13,15 @@ async fn main() {
1413
.with_process(
1514
&p1,
1615
DeployProcessSpec::new({
17-
HydroflowCrate::new(".", localhost.clone())
16+
HydroflowCrate::new(".", deployment.Localhost())
1817
.bin("first_ten_distributed")
1918
.profile("dev")
2019
}),
2120
)
2221
.with_process(
2322
&p2,
2423
DeployProcessSpec::new({
25-
HydroflowCrate::new(".", localhost.clone())
24+
HydroflowCrate::new(".", deployment.Localhost())
2625
.bin("first_ten_distributed")
2726
.profile("dev")
2827
}),

template/hydroflow_plus/flow/src/first_ten_distributed.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ mod tests {
4141
#[tokio::test]
4242
async fn first_ten_distributed() {
4343
let mut deployment = Deployment::new();
44-
let localhost = deployment.Localhost();
4544

4645
let flow = hydroflow_plus::FlowBuilder::new();
4746
let (p1, p2) = super::first_ten_distributed(&flow);
@@ -51,15 +50,15 @@ mod tests {
5150
.with_process(
5251
&p1,
5352
DeployProcessSpec::new({
54-
HydroflowCrate::new(".", localhost.clone())
53+
HydroflowCrate::new(".", deployment.Localhost())
5554
.bin("first_ten_distributed")
5655
.profile("dev")
5756
}),
5857
)
5958
.with_process(
6059
&p2,
6160
DeployProcessSpec::new({
62-
HydroflowCrate::new(".", localhost.clone())
61+
HydroflowCrate::new(".", deployment.Localhost())
6362
.bin("first_ten_distributed")
6463
.profile("dev")
6564
}),

0 commit comments

Comments
 (0)