Skip to content

Commit

Permalink
feat: specify worker count by CLI option
Browse files Browse the repository at this point in the history
This makes centipede configs portable across machines.
  • Loading branch information
max-niederman committed Apr 22, 2024
1 parent 713e521 commit 4601117
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
9 changes: 7 additions & 2 deletions packages/centipede/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ mod config;
struct Opt {
/// Path to config file.
config: PathBuf,

/// Number of workers to spawn.
/// Defaults to the number of CPUs.
#[clap(long, short, default_value_t = num_cpus::get())]
workers: usize,
}

fn main() -> Result<()> {
Expand Down Expand Up @@ -68,7 +73,7 @@ fn main() -> Result<()> {
.with_name(config.interface_name)
.with_address(config.address.address())
.with_netmask(config.address.network())
.with_num_queues(config.workers)
.with_num_queues(opt.workers)
.build()
.into_diagnostic()
.wrap_err("failed to create tun device")?;
Expand Down Expand Up @@ -150,7 +155,7 @@ fn main() -> Result<()> {
});
}

for i in 1..config.workers {
for i in 1..opt.workers {
let shutdown = shutdown.clone();
let mut worker = Worker::new(
router.worker(),
Expand Down
1 change: 0 additions & 1 deletion peer1.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ address = "10.0.10.1/24"
private_key = "hteZOax4E+ELo6q5eSVoFAhh9awJudkYhzUJDvguNU0="
recv_addrs = ["10.0.1.1:5000"]
interface_name = "cp1"
workers = 1

[[peers]]
public_key = "Wx0KV+g6TkuSIbUF/FUEztkchnRw7akTxJ8JV8QcJi0="
Expand Down
1 change: 0 additions & 1 deletion peer2.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ address = "10.0.10.2/24"
private_key = "QJVxWbA6o/3kk5znUyD5rySYe+yG829uGNoh2PNVyxk="
recv_addrs = ["10.0.1.2:5000"]
interface_name = "cp1"
workers = 1

[[peers]]
public_key = "Gb1SnzVaODF8LHKoBD+dJtS/e/9GYEhnLX0sOk8OIbA="
Expand Down

0 comments on commit 4601117

Please sign in to comment.