Skip to content

Commit 34257c9

Browse files
committed
fix: build examples also in ci, exclude msg-sim examples on non-linux target
1 parent 904ca40 commit 34257c9

File tree

5 files changed

+214
-194
lines changed

5 files changed

+214
-194
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ jobs:
100100
cache-on-failure: true
101101

102102
- name: Build all crates
103-
run: cargo build --all --all-features
103+
run: cargo build --all --all-features --examples
104104

105105
- name: Build release
106-
run: cargo build --all --all-features --release
106+
run: cargo build --all --all-features --examples --release
107107

108108
cargo-doc:
109109
runs-on: ubuntu-latest
@@ -123,7 +123,7 @@ jobs:
123123
run: RUSTDOCFLAGS="-D warnings" cargo +nightly doc --all --no-deps --all-features --document-private-items
124124
env:
125125
RUSTDOCFLAGS: "-D warnings"
126-
126+
127127
# Find unused dependencies, this will fail if any are found.
128128
cargo-shear:
129129
runs-on: ubuntu-latest

msg-sim/Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ tokio = { version = "1", features = [
3333
"net",
3434
] }
3535

36+
37+
[[example]]
38+
name = "bdp_throughput"
39+
3640
[[example]]
3741
name = "sim_multi_region"
38-
path = "examples/sim_multi_region.rs"
42+
43+
[[example]]
44+
name = "tcp_tuning"

msg-sim/examples/bdp_throughput.rs

Lines changed: 65 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -10,73 +10,77 @@
1010
//! sudo HOME=$HOME $(which cargo) run --example bdp_throughput -p msg-sim
1111
//! ```
1212
13-
use std::{
14-
net::{IpAddr, Ipv4Addr, SocketAddr},
15-
time::Instant,
16-
};
17-
18-
use futures::StreamExt;
19-
use msg_sim::{
20-
ip::Subnet,
21-
network::{Link, Network, PeerIdExt},
22-
tc::impairment::LinkImpairment,
23-
};
24-
use msg_socket::{RepSocket, ReqSocket};
25-
use msg_transport::tcp::Tcp;
26-
use tracing_subscriber::EnvFilter;
27-
28-
const BANDWIDTH_MBIT: f64 = 10.0;
29-
const MSG_SIZE: usize = 256 * 1024; // 256 KB per message
30-
const NUM_MESSAGES: usize = 20; // Send multiple to let cwnd grow
31-
const LATENCY_MS: u32 = 20; // 20ms one-way = 40ms RTT
32-
33-
const TCP_RMEM: &str = "/proc/sys/net/ipv4/tcp_rmem";
34-
const TCP_WINDOW_SCALING: &str = "/proc/sys/net/ipv4/tcp_window_scaling";
35-
36-
/// Transfer multiple messages and measure throughput
37-
async fn transfer(network: &Network, sender: usize, receiver: usize, addr: SocketAddr) -> f64 {
38-
let server = network
39-
.run_in_namespace(receiver, move |_| {
40-
Box::pin(async move {
41-
let mut rep = RepSocket::new(Tcp::default());
42-
rep.bind(addr).await.unwrap();
43-
for _ in 0..NUM_MESSAGES {
44-
if let Some(req) = rep.next().await {
45-
req.respond("ok".into()).unwrap();
13+
#[cfg(not(target_os = "linux"))]
14+
fn main() {}
15+
16+
#[cfg(target_os = "linux")]
17+
#[tokio::main]
18+
async fn main() -> Result<(), Box<dyn std::error::Error>> {
19+
use std::{
20+
net::{IpAddr, Ipv4Addr, SocketAddr},
21+
time::Instant,
22+
};
23+
24+
use futures::StreamExt;
25+
use msg_sim::{
26+
ip::Subnet,
27+
network::{Link, Network, PeerIdExt},
28+
tc::impairment::LinkImpairment,
29+
};
30+
use msg_socket::{RepSocket, ReqSocket};
31+
use msg_transport::tcp::Tcp;
32+
use tracing_subscriber::EnvFilter;
33+
34+
const BANDWIDTH_MBIT: f64 = 10.0;
35+
const MSG_SIZE: usize = 256 * 1024; // 256 KB per message
36+
const NUM_MESSAGES: usize = 20; // Send multiple to let cwnd grow
37+
const LATENCY_MS: u32 = 20; // 20ms one-way = 40ms RTT
38+
39+
const TCP_RMEM: &str = "/proc/sys/net/ipv4/tcp_rmem";
40+
const TCP_WINDOW_SCALING: &str = "/proc/sys/net/ipv4/tcp_window_scaling";
41+
42+
/// Transfer multiple messages and measure throughput
43+
async fn transfer(network: &Network, sender: usize, receiver: usize, addr: SocketAddr) -> f64 {
44+
let server = network
45+
.run_in_namespace(receiver, move |_| {
46+
Box::pin(async move {
47+
let mut rep = RepSocket::new(Tcp::default());
48+
rep.bind(addr).await.unwrap();
49+
for _ in 0..NUM_MESSAGES {
50+
if let Some(req) = rep.next().await {
51+
req.respond("ok".into()).unwrap();
52+
}
4653
}
47-
}
54+
})
4855
})
49-
})
50-
.await
51-
.unwrap();
52-
53-
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
54-
55-
let client = network
56-
.run_in_namespace(sender, move |_| {
57-
Box::pin(async move {
58-
let mut req = ReqSocket::new(Tcp::default());
59-
req.connect_sync(addr);
60-
let payload = vec![0u8; MSG_SIZE];
61-
let start = Instant::now();
62-
for _ in 0..NUM_MESSAGES {
63-
req.request(payload.clone().into()).await.unwrap();
64-
}
65-
start.elapsed()
56+
.await
57+
.unwrap();
58+
59+
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
60+
61+
let client = network
62+
.run_in_namespace(sender, move |_| {
63+
Box::pin(async move {
64+
let mut req = ReqSocket::new(Tcp::default());
65+
req.connect_sync(addr);
66+
let payload = vec![0u8; MSG_SIZE];
67+
let start = Instant::now();
68+
for _ in 0..NUM_MESSAGES {
69+
req.request(payload.clone().into()).await.unwrap();
70+
}
71+
start.elapsed()
72+
})
6673
})
67-
})
68-
.await
69-
.unwrap();
74+
.await
75+
.unwrap();
7076

71-
let (elapsed, _) = tokio::try_join!(client, server).unwrap();
72-
println!("Transfer elapsed: {elapsed:?}");
77+
let (elapsed, _) = tokio::try_join!(client, server).unwrap();
78+
println!("Transfer elapsed: {elapsed:?}");
7379

74-
let total_bytes = MSG_SIZE * NUM_MESSAGES;
75-
(total_bytes as f64 * 8.0) / (elapsed.as_secs_f64() * 1_000_000.0)
76-
}
80+
let total_bytes = MSG_SIZE * NUM_MESSAGES;
81+
(total_bytes as f64 * 8.0) / (elapsed.as_secs_f64() * 1_000_000.0)
82+
}
7783

78-
#[tokio::main]
79-
async fn main() -> Result<(), Box<dyn std::error::Error>> {
8084
tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init();
8185

8286
let rtt_ms = LATENCY_MS * 2;

0 commit comments

Comments
 (0)