Skip to content

Commit 317678e

Browse files
committed
perf(pegboard): parallelize download image & setup cni network
1 parent 5852e82 commit 317678e

File tree

1 file changed

+27
-13
lines changed
  • packages/edge/infra/client/manager/src/actor

1 file changed

+27
-13
lines changed

packages/edge/infra/client/manager/src/actor/mod.rs

+27-13
Original file line numberDiff line numberDiff line change
@@ -139,23 +139,37 @@ impl Actor {
139139
.await
140140
.context("failed to create actor dir")?;
141141

142-
// Create fs mount
143-
self.make_fs(&ctx).await?;
144-
145-
// Download artifact
146-
self.download_image(&ctx).await?;
147-
148-
// Bind selected ports
149-
let ports = self.bind_ports(ctx).await?;
142+
// Determine ahead of time if we need to set up CNI network
143+
let needs_cni_network = matches!(
144+
self.config.image.kind,
145+
protocol::ImageKind::DockerImage | protocol::ImageKind::OciBundle
146+
) && matches!(self.config.network_mode, protocol::NetworkMode::Bridge);
147+
148+
// Parallelize two independent jobs:
149+
//
150+
// - `download_image` takes a long time to download. `download_image` is dependent on
151+
// `make_fs`
152+
// - `setup_cni_network` takes a long time. `setup_cni_network` is dependent on
153+
// `bind_ports`.
154+
let (_, ports) = tokio::try_join!(
155+
async {
156+
self.make_fs(&ctx).await?;
157+
self.download_image(&ctx).await?;
158+
Result::<(), anyhow::Error>::Ok(())
159+
},
160+
async {
161+
let ports = self.bind_ports(ctx).await?;
162+
if needs_cni_network {
163+
self.setup_cni_network(&ctx, &ports).await?;
164+
}
165+
166+
Ok(ports)
167+
}
168+
)?;
150169

151170
match self.config.image.kind {
152171
protocol::ImageKind::DockerImage | protocol::ImageKind::OciBundle => {
153172
self.setup_oci_bundle(&ctx, &ports).await?;
154-
155-
// Run CNI setup script
156-
if let protocol::NetworkMode::Bridge = self.config.network_mode {
157-
self.setup_cni_network(&ctx, &ports).await?;
158-
}
159173
}
160174
protocol::ImageKind::JavaScript => self.setup_isolate(&ctx, &ports).await?,
161175
}

0 commit comments

Comments
 (0)