Skip to content

Commit

Permalink
Switch to toml for deployment config
Browse files Browse the repository at this point in the history
  • Loading branch information
imDema committed Mar 14, 2024
1 parent 17a2b60 commit e8c6b0c
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 70 deletions.
61 changes: 47 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ nanorand = "0.7.0"
# utility macros for customizing the derive Debug, Default, ...
derivative = "2.2.0"

# serialization library used for reading the config file (yaml) and serializing
# the messages on the network
# serialization
serde = { version = "1.0.197", features = ["derive"] }
serde_yaml = "0.9.32"
serde_json = "1.0.114"
bincode = "1.3.3"
toml = "0.8.11"

# handy Result type
anyhow = "1.0.81"
Expand Down
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,23 @@ fn tokenize(s: &str) -> Vec<String> {
s.split_whitespace().map(str::to_lowercase).collect()
}

// Execute on multiple hosts `cargo run -- -r config.yaml input.txt`
// Execute on multiple hosts `cargo run -- -r config.toml input.txt`
```

### Remote deployment

```yaml
# config.yaml
hosts:
- address: host1.lan
base_port: 9500
num_cores: 16
- address: host2.lan
base_port: 9500
num_cores: 8
ssh:
username: noir-compute
key_file: /home/user/.ssh/id_rsa
```toml
# config.toml
[[host]]
address = "host1.lan"
base_port = 9500
num_cores = 16

[[host]]
address = "host2.lan"
base_port = 9500
num_cores = 24
ssh = { username = "noir", key_file = "/home/noir/.ssh/id_ed25519" }
```

Refer to the [examples](examples/) directory for an extended set of working examples
6 changes: 3 additions & 3 deletions examples/nexmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,11 +465,11 @@ fn main() {
tracing_subscriber::fmt::init();

let (config, args) = RuntimeConfig::from_args();
if args.len() != 2 {
if args.len() != 3 {
panic!("Pass the element count as argument");
}
let n: usize = args[0].parse().unwrap();
let q = &args[1][..];
let n: usize = args[1].parse().unwrap();
let q = &args[2][..];
config.spawn_remote_workers();
let env = StreamContext::new(config);

Expand Down
31 changes: 17 additions & 14 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub const CONFIG_ENV_VAR: &str = "NOIR_CONFIG";
/// and remote workers).
///
/// In a remote execution the current binary is copied using scp to a remote host and then executed
/// using ssh. The configuration of the remote environment should be specified via a YAML
/// using ssh. The configuration of the remote environment should be specified via a TOML
/// configuration file.
///
/// ## Local environment
Expand All @@ -47,19 +47,21 @@ pub const CONFIG_ENV_VAR: &str = "NOIR_CONFIG";
/// # use noir_compute::{StreamContext, RuntimeConfig};
/// # use std::fs::File;
/// # use std::io::Write;
/// let config = r"
/// hosts:
/// - address: host1
/// base_port: 9500
/// num_cores: 16
/// - address: host2
/// base_port: 9500
/// num_cores: 24
/// ";
/// let mut file = File::create("config.yaml").unwrap();
/// let config = r#"
/// [[host]]
/// address = "host1"
/// base_port = 9500
/// num_cores = 16
///
/// [[host]]
/// address = "host2"
/// base_port = 9500
/// num_cores = 24
/// "#;
/// let mut file = File::create("config.toml").unwrap();
/// file.write_all(config.as_bytes());
///
/// let config = RuntimeConfig::remote("config.yaml").expect("cannot read config file");
/// let config = RuntimeConfig::remote("config.toml").expect("cannot read config file");
/// let env = StreamContext::new(config);
/// ```
///
Expand Down Expand Up @@ -106,6 +108,7 @@ pub struct RemoteConfig {
#[serde(skip)]
pub host_id: Option<HostId>,
/// The set of remote hosts to use.
#[serde(rename = "host")]
pub hosts: Vec<HostConfig>,
/// If specified some debug information will be stored inside this directory.
pub tracing_dir: Option<PathBuf>,
Expand Down Expand Up @@ -233,7 +236,7 @@ impl RuntimeConfig {
} else {
log::info!("reading config from: {}", config.as_ref().display());
let content = std::fs::read_to_string(config)?;
serde_yaml::from_str(&content)?
toml::from_str(&content)?
};

// validate the configuration
Expand Down Expand Up @@ -274,7 +277,7 @@ impl RuntimeConfig {
Ok(config) => {
info!("reading remote config from env {}", CONFIG_ENV_VAR);
let config: RemoteConfig =
serde_yaml::from_str(&config).expect("Invalid configuration from environment");
toml::from_str(&config).expect("Invalid configuration from environment");
Some(config)
}
Err(_) => None,
Expand Down
26 changes: 13 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,23 @@ fn tokenize(s: &str) -> Vec<String> {
s.split_whitespace().map(str::to_lowercase).collect()
}
// Execute on multiple hosts `cargo run -- -r config.yaml input.txt`
// Execute on multiple hosts `cargo run -- -r config.toml input.txt`
```
### Remote deployment
```yaml
# config.yaml
hosts:
- address: host1.lan
base_port: 9500
num_cores: 16
- address: host2.lan
base_port: 9500
num_cores: 8
ssh:
username: noir-compute
key_file: /home/user/.ssh/id_rsa
```toml
# config.toml
[[host]]
address = "host1.lan"
base_port = 9500
num_cores = 16
[[host]]
address = "host2.lan"
base_port = 9500
num_cores = 24
ssh = { username = "noir", key_file = "/home/noir/.ssh/id_ed25519" }
```
Refer to the [examples](examples/) directory for an extended set of working examples
Expand Down
18 changes: 10 additions & 8 deletions src/network/topology.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,14 +631,16 @@ mod tests {
#[test]
fn test_remote_topology() {
let mut config = tempfile::NamedTempFile::new().unwrap();
let config_yaml = "hosts:\n".to_string()
+ " - address: 127.0.0.1\n"
+ " base_port: 21841\n"
+ " num_cores: 1\n"
+ " - address: 127.0.0.1\n"
+ " base_port: 31258\n"
+ " num_cores: 1\n";
std::io::Write::write_all(&mut config, config_yaml.as_bytes()).unwrap();
let config_toml = r#"[[host]]
address = "127.0.0.1"
base_port = 21841
num_cores = 1
[[host]]
address = "127.0.0.1"
base_port = 31258
num_cores = 1
"#;
std::io::Write::write_all(&mut config, config_toml.as_bytes()).unwrap();
let config = RuntimeConfig::remote(config.path()).unwrap();

// s1 [b0, h0, r0] -> r1 [b2, h1, r0] (endpoint 1) type=i32
Expand Down
4 changes: 2 additions & 2 deletions src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,8 @@ fn build_remote_command(
binary_path: &Path,
perf_path: &Option<PathBuf>,
) -> String {
let config_yaml = serde_yaml::to_string(config).unwrap();
let config_str = shell_escape::escape(config_yaml.into());
let config_toml = toml::to_string(config).unwrap();
let config_str = shell_escape::escape(config_toml.into());
let args = std::env::args()
.skip(1)
.map(|arg| shell_escape::escape(arg.into()))
Expand Down

0 comments on commit e8c6b0c

Please sign in to comment.