Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Auto-detect available system resources #131

Merged
merged 2 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions crates/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ home = { version = "0.5", optional = true}
http-body-util = { version = "0.1", optional = true }
hyper = { version = "1", features = ["full"], optional = true }
hyper-util = { version = "0.1", features = ["full"], optional = true }
num_cpus = { version = "1.4.0", optional = true }
num-traits = { version = "0.2", optional = true }
parking_lot = { version = "0.12", optional = true }
pea2pea = { version = "0.48", optional = true }
prost = { version = "0.11", optional = true }
qapi = { version = "0.14", features = [ "qmp", "async-tokio-net" ], optional = true }
snow = { version = "0.9", optional = true }
systemstat = { version = "0.2.3", optional = true }
tokio-stream = { version = "0.1", optional = true }
tokio-util = { version = "0.7", optional = true }
tokio-vsock = { version = "0.4.0", features = ["tonic-conn"], optional = true }
Expand All @@ -62,12 +64,14 @@ node-binary = [
"http-body-util",
"hyper",
"hyper-util",
"num_cpus",
"num-traits",
"parking_lot",
"pea2pea",
"prost",
"qapi",
"snow",
"systemstat",
"tokio-stream",
"tokio-util",
"tokio-vsock",
Expand Down
14 changes: 4 additions & 10 deletions crates/node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,15 @@ pub struct Config {
)]
pub vsock_listen_port: u32,

#[arg(
long,
long_help = "Number of CPUs available",
env = "GEVULOT_CPUS",
default_value_t = 8
)]
pub num_cpus: u64,
#[arg(long, long_help = "Number of CPUs available", env = "GEVULOT_CPUS")]
pub num_cpus: Option<u64>,

#[arg(
long,
long_help = "Amount of memory available (in GBs)",
env = "GEVULOT_MEM_GB",
default_value_t = 8
env = "GEVULOT_MEM_GB"
)]
pub mem_gb: u64,
pub mem_gb: Option<u64>,

#[arg(long, long_help = "GPU PCI devices", env = "GEVULOT_GPU_DEVICES")]
pub gpu_devices: Option<String>,
Expand Down
26 changes: 23 additions & 3 deletions crates/node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use std::{
thread::sleep,
time::Duration,
};
use systemstat::{ByteSize, Platform, System};
use tokio::sync::mpsc;
use tokio::sync::{Mutex as TMutex, RwLock};
use tokio_stream::wrappers::UnboundedReceiverStream;
Expand Down Expand Up @@ -234,11 +235,30 @@ async fn run(config: Arc<Config>) -> Result<()> {
let p2p_listen_addr = p2p.node().start_listening().await?;
tracing::info!("listening for p2p at {}", p2p_listen_addr);

// TODO(tuommaki): read total available resources from config / acquire system stats.
let sys = System::new();
let num_gpus = if config.gpu_devices.is_some() { 1 } else { 0 };
let num_cpus = match config.num_cpus {
Some(cpus) => cpus,
None => num_cpus::get() as u64,
};
let available_mem = match config.mem_gb {
Some(mem_gb) => mem_gb * 1024 * 1024 * 1024,
None => {
let mem = sys.memory()?;
mem.total.as_u64()
}
};

tracing::info!(
"node configured with {} CPUs, {} MEM and {} GPUs",
num_cpus,
ByteSize(available_mem).to_string_as(true),
num_gpus
);

let resource_manager = Arc::new(Mutex::new(scheduler::ResourceManager::new(
config.mem_gb * 1024 * 1024 * 1024,
config.num_cpus,
available_mem,
num_cpus,
num_gpus,
)));

Expand Down
4 changes: 2 additions & 2 deletions crates/node/src/rpc_server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,8 @@ mod tests {
p2p_advertised_listen_addr: None,
provider: "qemu".to_string(),
vsock_listen_port: 8080,
num_cpus: 8,
mem_gb: 8,
num_cpus: None,
mem_gb: None,
gpu_devices: None,
http_download_port: 0,
});
Expand Down
Loading