Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jjanowsk committed Dec 4, 2024
1 parent db16cad commit 35a5a40
Show file tree
Hide file tree
Showing 12 changed files with 269 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[target.'cfg(unix)']
runner = 'sudo -E'
[alias]
xtask = "run --package xtask --"
9 changes: 9 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,12 @@ jobs:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
- uses: actions-rs/toolchain@b2417cde72dcf67f306c0ae8e0828a81bf0b189f # v1.0.6
- run: cargo bench -p neptun --no-run

performance-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
with:
fetch-depth: 0
- run: docker build -t neptun-runner:0.0.1 .
- run: cargo xtask perf --base LLT-5809-socket-reader
49 changes: 49 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
resolver = "2"
members = ["neptun", "neptun-cli"]
members = ["neptun", "neptun-cli", "xtask"]

[profile.release]
lto = true # Enable full link-time optimization.
Expand Down
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM debian:bookworm-slim
RUN apt-get update && apt-get install --no-install-recommends -y \
iperf3 \
iproute2 \
iputils-ping \
net-tools \
wireguard-go \
wireguard-tools \
&& rm -rf /var/lib/apt/lists/*
2 changes: 1 addition & 1 deletion neptun-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ fn main() {
use_connected_socket: !matches.get_flag("disable-connected-udp"),
#[cfg(target_os = "linux")]
use_multi_queue: !matches.get_flag("disable-multi-queue"),
open_uapi_socket: false,
open_uapi_socket: true,
protect: Arc::new(neptun::device::MakeExternalNeptunNoop),
firewall_process_inbound_callback: None,
firewall_process_outbound_callback: None,
Expand Down
11 changes: 11 additions & 0 deletions xtask/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "xtask"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "1.0"
clap = { version = "4.5", features = ["derive"] }
xshell = "0.2.7"
45 changes: 45 additions & 0 deletions xtask/perf/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
version: '3.2'

services:
left:
hostname: left
container_name: left
image: neptun-runer:0.0.1
entrypoint: /neptun/config/left.sh
privileged: true
depends_on:
right:
condition: service_healthy
networks:
default:
ipv4_address: 176.0.0.2
volumes:
- ../../target/release:/neptun/current
- ../../base/target/release:/neptun/base
- .:/neptun/config

right:
hostname: right
container_name: right
image: neptun-runer:0.0.1
entrypoint: /neptun/config/right.sh
privileged: true
healthcheck:
test: ["CMD-SHELL", "cat /.iperf_ready"]
interval: 1s
start_interval: 1s
start_period: 60s
networks:
default:
ipv4_address: 176.0.0.3
volumes:
- ../../target/release:/neptun/current
- ../../base/target/release:/neptun/base
- .:/neptun/config

networks:
default:
driver: bridge
ipam:
config:
- subnet: 176.0.0.0/24
36 changes: 36 additions & 0 deletions xtask/perf/left.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

wireguard-go wg0
wg set wg0 \
listen-port 51820 \
private-key <(echo AH7jKt6M0RS21MkRG+URrfgmwvJqdhVvqtKeF4WR+E8=) \
peer mqrc8+LD+6zvMeCtyCcIBPEYuXT74lq1Hros0Np8ZgA= \
allowed-ips 10.0.0.2/32 \
endpoint 176.0.0.3:51820
ip address add dev wg0 10.0.0.1/24
ip link set up dev wg0

/neptun/base/neptun-cli --disable-drop-privileges wg1
wg set wg1 \
listen-port 51821 \
private-key <(echo sKZoT3qgxDm1bWny+1ttoi00qS2KXvo1L4Zb265wr3c=) \
peer CMWokCGH+YPN7CL2C2aAkDlnhw1blH0tKPOnEOgzrxM= \
allowed-ips 10.0.1.2/32 \
endpoint 176.0.0.3:51821
ip address add dev wg1 10.0.1.1/24
ip link set up dev wg1

/neptun/current/neptun-cli --disable-drop-privileges wg2
wg set wg2 \
listen-port 51822 \
private-key <(echo 0Fn5JWI1QGDiaVYLDBSLklIEBUujfpX1oH/UGI2D62k=) \
peer fqrU1Wk8nuyy6phf8IUDwcKK1ElslFYDyteANr2hlgM= \
allowed-ips 10.0.2.2/32 \
endpoint 176.0.0.3:51822
ip address add dev wg2 10.0.2.1/24
ip link set up dev wg2

iperf3 -i 60 -t 120 --bidir -c 176.0.0.3
iperf3 -i 60 -t 120 --bidir -c 10.0.0.2
iperf3 -i 60 -t 120 --bidir -c 10.0.1.2
iperf3 -i 60 -t 120 --bidir -c 10.0.2.2
35 changes: 35 additions & 0 deletions xtask/perf/right.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

wireguard-go wg0
wg set wg0 \
listen-port 51820 \
private-key <(echo MLBFYI9O69v8WdVodp4YucqnvW+onpD/R5kF/GE18F8=) \
peer 7gr2QZyPpaIdlsPcZcQozgpjDdCkefZtxz12Dmpj/3Y= \
allowed-ips 10.0.0.1/32 \
endpoint 176.0.0.2:51820
ip address add dev wg0 10.0.0.2/24
ip link set up dev wg0

/neptun/base/neptun-cli --disable-drop-privileges wg1
wg set wg1 \
listen-port 51821 \
private-key <(echo WAoFbPJ6QaXXltwLqBADFkMG6qLZuivSlkIUv2Sc3lY=) \
peer HcDZRTIcI3Yok4XTwhAScKoNkb9MIZ2wyjS1oQvZnic= \
allowed-ips 10.0.1.1/32 \
endpoint 176.0.0.2:51821
ip address add dev wg1 10.0.1.2/24
ip link set up dev wg1

/neptun/current/neptun-cli --disable-drop-privileges wg2
wg set wg2 \
listen-port 51822 \
private-key <(echo eNOePaXKpyN9IjNEDe1a4CzBAwdbLupbF5wfdCUjS18=) \
peer zj6KZHkVw3ILScBGgUaYfuRkwhK6GgrIHmzfd4MPx1k= \
allowed-ips 10.0.2.1/32 \
endpoint 176.0.0.2:51822
ip address add dev wg2 10.0.2.2/24
ip link set up dev wg2

iperf3 -s > /dev/null &
touch /.iperf_ready
sleep infinity
15 changes: 15 additions & 0 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
mod perf;

use clap::Parser;

#[derive(Parser, Debug)]
enum Cmd {
/// Run performance benchmark
Perf(perf::Cmd),
}

fn main() {
match Cmd::parse() {
Cmd::Perf(perf) => perf.run(),
}
}
56 changes: 56 additions & 0 deletions xtask/src/perf.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use anyhow::Result;
use clap::Parser;
use xshell::{cmd, Shell};

#[derive(Parser, Debug)]
pub struct Cmd {
/// Git ref of the benchmark base
#[arg(short, long)]
base: String,
}

struct GitWorktree {
name: String,
sh: Shell,
}

impl GitWorktree {
fn new(name: &str, base_ref: &str) -> Self {
let sh = Shell::new().expect("Failed to create shell object");
cmd!(sh, "git worktree add {name} {base_ref}")
.run()
.expect("Failed to create base worktree");
GitWorktree {
name: name.to_string(),
sh: sh,
}
}
}

impl Drop for GitWorktree {
fn drop(&mut self) {
let name = &self.name;
_ = cmd!(self.sh, "git worktree remove {name}").run();
}
}

fn build_neptun_cli(dir: &str) {
let sh = Shell::new().expect("Failed to create shell object");
sh.change_dir(dir);
cmd!(sh, "cargo build --release -p neptun-cli")
.run()
.expect("Failed to build base version");
}

impl Cmd {
pub fn run(&self) {
let worktree = GitWorktree::new("base", &self.base);
build_neptun_cli(".");
build_neptun_cli(&worktree.name);

let sh = Shell::new().expect("Failed to create shell object");
cmd!(sh, "docker compose -f xtask/perf/docker-compose.yml up --abort-on-container-exit")
.run()
.expect("Failed to build base version");
}
}

0 comments on commit 35a5a40

Please sign in to comment.