pub struct Config {
pub mode: Mode,
pub protocol: Protocol,
pub port: u16,
pub server_addr: Option<String>,
pub bind_addr: Option<IpAddr>,
pub duration: Duration,
pub bandwidth: Option<u64>,
pub buffer_size: usize,
pub parallel: usize,
pub reverse: bool,
pub json: bool,
pub interval: Duration,
}Expand description
Configuration for rperf3 network performance tests.
This structure holds all configuration parameters for both client and server modes. Use the builder pattern methods to customize the configuration.
§Examples
§Basic TCP Client
use rperf3::Config;
use std::time::Duration;
let config = Config::client("192.168.1.100".to_string(), 5201)
.with_duration(Duration::from_secs(30))
.with_buffer_size(256 * 1024); // 256 KB buffer§UDP Client with Bandwidth Limit
use rperf3::{Config, Protocol};
use std::time::Duration;
let config = Config::client("192.168.1.100".to_string(), 5201)
.with_protocol(Protocol::Udp)
.with_bandwidth(100_000_000) // 100 Mbps
.with_duration(Duration::from_secs(10));§Server Configuration
use rperf3::Config;
let config = Config::server(5201);§Reverse Mode Test
use rperf3::Config;
use std::time::Duration;
// Server sends data, client receives
let config = Config::client("192.168.1.100".to_string(), 5201)
.with_reverse(true)
.with_duration(Duration::from_secs(10));Fields§
§mode: ModeServer mode or client mode
protocol: ProtocolProtocol to use (TCP or UDP)
port: u16Port number to use
server_addr: Option<String>Server address (for client mode)
bind_addr: Option<IpAddr>Bind address (for server mode)
duration: DurationTest duration in seconds
bandwidth: Option<u64>Target bandwidth in bits per second (for UDP)
buffer_size: usizeBuffer size in bytes
parallel: usizeNumber of parallel streams
reverse: boolReverse mode (server sends, client receives)
json: boolOutput in JSON format
interval: DurationInterval for periodic bandwidth reports in seconds
Implementations§
Source§impl Config
impl Config
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new configuration with default values.
This is equivalent to calling Config::default(). The default configuration
is set up for client mode with TCP protocol.
§Examples
use rperf3::Config;
let config = Config::new();
assert_eq!(config.port, 5201);Sourcepub fn server(port: u16) -> Self
pub fn server(port: u16) -> Self
Creates a new server configuration.
Sets up the configuration for server mode, which listens for incoming connections on the specified port.
§Arguments
port- The port number to listen on (typically 5201)
§Examples
use rperf3::Config;
let config = Config::server(5201);Examples found in repository?
4async fn main() -> Result<(), Box<dyn std::error::Error>> {
5 env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
6
7 println!("Starting rperf3 server on port 5201...");
8
9 let config = Config::server(5201).with_protocol(Protocol::Tcp);
10
11 let server = Server::new(config);
12 server.run().await?;
13
14 Ok(())
15}More examples
30async fn run_server() -> Result<(), Box<dyn std::error::Error>> {
31 println!("Starting TCP server on port 5201...");
32 println!("Press Ctrl+C to stop the server gracefully.\n");
33
34 let config = Config::server(5201);
35 let server = Server::new(config);
36
37 // Clone the cancellation token to handle CTRL+C
38 let cancel_token = server.cancellation_token().clone();
39
40 // Set up CTRL+C handler
41 tokio::spawn(async move {
42 tokio::signal::ctrl_c()
43 .await
44 .expect("Failed to listen for CTRL+C");
45 println!("\nReceived CTRL+C, shutting down server gracefully...");
46 cancel_token.cancel();
47 });
48
49 server.run().await?;
50 println!("Server stopped.");
51 Ok(())
52}17async fn main() -> Result<(), Box<dyn std::error::Error>> {
18 // Initialize logging
19 env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
20
21 println!("TCP Socket Optimization Demo");
22 println!("============================\n");
23 println!("This demo tests TCP with:");
24 println!("- TCP_NODELAY enabled (Nagle's algorithm disabled)");
25 println!("- 256KB send/receive buffers");
26 println!("- Expected 10-20% improvement over default settings\n");
27
28 // Start server in background
29 let server_config = Config::server(5201).with_protocol(Protocol::Tcp);
30 let server = Server::new(server_config);
31
32 // Run server in background task
33 tokio::spawn(async move {
34 if let Err(e) = server.run().await {
35 eprintln!("Server error: {}", e);
36 }
37 });
38
39 // Give server time to start
40 time::sleep(Duration::from_millis(100)).await;
41
42 println!("Starting TCP test (5 seconds)...\n");
43
44 // Run client test
45 let client_config = Config::client("127.0.0.1".to_string(), 5201)
46 .with_protocol(Protocol::Tcp)
47 .with_duration(Duration::from_secs(5))
48 .with_interval(Duration::from_secs(1));
49
50 let client = Client::new(client_config)?;
51 client.run().await?;
52
53 // Get measurements
54 let measurements = client.get_measurements();
55 let total_bytes = measurements.total_bytes_sent + measurements.total_bytes_received;
56 let bits_per_second = measurements.total_bits_per_second();
57
58 println!("\n=== Results ===");
59 println!(
60 "Total transferred: {:.2} MB",
61 total_bytes as f64 / 1_000_000.0
62 );
63 println!("Throughput: {:.2} Mbps", bits_per_second / 1_000_000.0);
64 println!("\nSocket optimizations applied:");
65 println!("✓ TCP_NODELAY: enabled");
66 println!("✓ Send buffer: 256KB");
67 println!("✓ Recv buffer: 256KB");
68
69 Ok(())
70}12async fn main() -> Result<(), Box<dyn std::error::Error>> {
13 env_logger::init();
14
15 let args: Vec<String> = std::env::args().collect();
16 let mode = args.get(1).map(|s| s.as_str()).unwrap_or("client");
17
18 match mode {
19 "server" => {
20 println!("Starting TCP server on port 5201...");
21 println!("Retransmits will be shown if they occur during the test.\n");
22
23 let config = Config::server(5201);
24 let server = Server::new(config);
25 server.run().await?;
26 }
27 "client" => {
28 println!("Starting TCP client test (10 seconds)...");
29 println!("Retransmits will be tracked and displayed per interval.\n");
30
31 let config = Config::client("127.0.0.1".to_string(), 5201)
32 .with_duration(Duration::from_secs(10));
33
34 let client = Client::new(config)?.with_callback(|event: ProgressEvent| match event {
35 ProgressEvent::TestStarted => {
36 println!("Test started");
37 }
38 ProgressEvent::IntervalUpdate {
39 interval_start,
40 interval_end,
41 bits_per_second,
42 retransmits,
43 ..
44 } => {
45 if let Some(retrans) = retransmits {
46 println!(
47 "[{:.1}-{:.1}s] {:.2} Mbps - {} retransmits detected",
48 interval_start.as_secs_f64(),
49 interval_end.as_secs_f64(),
50 bits_per_second / 1_000_000.0,
51 retrans
52 );
53 } else {
54 println!(
55 "[{:.1}-{:.1}s] {:.2} Mbps - no retransmits",
56 interval_start.as_secs_f64(),
57 interval_end.as_secs_f64(),
58 bits_per_second / 1_000_000.0
59 );
60 }
61 }
62 ProgressEvent::TestCompleted {
63 total_bytes,
64 bits_per_second,
65 ..
66 } => {
67 println!("\nTest completed:");
68 println!(" Total bytes: {}", total_bytes);
69 println!(
70 " Average throughput: {:.2} Mbps",
71 bits_per_second / 1_000_000.0
72 );
73 println!("\nNote: Retransmit tracking is only available on Linux systems.");
74 }
75 ProgressEvent::Error(msg) => {
76 eprintln!("Error: {}", msg);
77 }
78 });
79
80 client.run().await?;
81 }
82 _ => {
83 eprintln!("Usage: {} [server|client]", args[0]);
84 std::process::exit(1);
85 }
86 }
87
88 Ok(())
89}Sourcepub fn client(server_addr: String, port: u16) -> Self
pub fn client(server_addr: String, port: u16) -> Self
Creates a new client configuration.
Sets up the configuration for client mode, which connects to a server at the specified address and port.
§Arguments
server_addr- The IP address or hostname of the serverport- The port number to connect to (typically 5201)
§Examples
use rperf3::Config;
let config = Config::client("192.168.1.100".to_string(), 5201);Examples found in repository?
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6 env_logger::init();
7
8 let config = Config::client("127.0.0.1".to_string(), 5201)
9 .with_duration(Duration::from_secs(3))
10 .with_json(true);
11
12 let client = Client::new(config)?;
13
14 match client.run().await {
15 Ok(_) => println!("\nTest completed successfully"),
16 Err(e) => eprintln!("\nError: {}", e),
17 }
18
19 Ok(())
20}More examples
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6 env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
7
8 println!("Connecting to rperf3 server at 127.0.0.1:5201...");
9
10 let config = Config::client("127.0.0.1".to_string(), 5201)
11 .with_protocol(Protocol::Tcp)
12 .with_duration(Duration::from_secs(10))
13 .with_buffer_size(128 * 1024);
14
15 let client = Client::new(config)?;
16 client.run().await?;
17
18 let measurements = client.get_measurements();
19 println!(
20 "\nFinal Results: {:.2} Mbps",
21 measurements.total_bits_per_second() / 1_000_000.0
22 );
23
24 Ok(())
25}5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6 env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
7
8 println!("Running UDP test with 50 Mbps target bandwidth...");
9
10 let config = Config::client("127.0.0.1".to_string(), 5201)
11 .with_protocol(Protocol::Udp)
12 .with_duration(Duration::from_secs(10))
13 .with_bandwidth(50 * 1_000_000) // 50 Mbps
14 .with_buffer_size(1024);
15
16 let client = Client::new(config)?;
17 client.run().await?;
18
19 let measurements = client.get_measurements();
20 println!(
21 "\nFinal Results: {:.2} Mbps",
22 measurements.total_bits_per_second() / 1_000_000.0
23 );
24
25 Ok(())
26}49async fn main() -> Result<(), Box<dyn std::error::Error>> {
50 env_logger::init();
51
52 println!("rperf3 Client with Callback Example");
53 println!("====================================\n");
54
55 // Configure the test
56 let config = Config::client("127.0.0.1".to_string(), 5201)
57 .with_protocol(Protocol::Tcp)
58 .with_duration(Duration::from_secs(10))
59 .with_buffer_size(128 * 1024)
60 .with_interval(Duration::from_secs(2)); // Report every 2 seconds
61
62 // Create client with custom callback
63 let client = Client::new(config)?.with_callback(MyProgressCallback);
64
65 println!("Connecting to server at 127.0.0.1:5201...\n");
66
67 // Run the test (callback will be invoked during execution)
68 client.run().await?;
69
70 // Get final measurements
71 let measurements = client.get_measurements();
72 println!("\n📈 Final Statistics:");
73 println!(" Total bytes: {}", measurements.total_bytes_sent);
74 println!(
75 " Duration: {:.2}s",
76 measurements.total_duration.as_secs_f64()
77 );
78 println!(
79 " Average bandwidth: {:.2} Mbps",
80 measurements.total_bits_per_second() / 1_000_000.0
81 );
82
83 Ok(())
84}17async fn main() -> Result<(), Box<dyn std::error::Error>> {
18 // Initialize logging
19 env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
20
21 println!("TCP Socket Optimization Demo");
22 println!("============================\n");
23 println!("This demo tests TCP with:");
24 println!("- TCP_NODELAY enabled (Nagle's algorithm disabled)");
25 println!("- 256KB send/receive buffers");
26 println!("- Expected 10-20% improvement over default settings\n");
27
28 // Start server in background
29 let server_config = Config::server(5201).with_protocol(Protocol::Tcp);
30 let server = Server::new(server_config);
31
32 // Run server in background task
33 tokio::spawn(async move {
34 if let Err(e) = server.run().await {
35 eprintln!("Server error: {}", e);
36 }
37 });
38
39 // Give server time to start
40 time::sleep(Duration::from_millis(100)).await;
41
42 println!("Starting TCP test (5 seconds)...\n");
43
44 // Run client test
45 let client_config = Config::client("127.0.0.1".to_string(), 5201)
46 .with_protocol(Protocol::Tcp)
47 .with_duration(Duration::from_secs(5))
48 .with_interval(Duration::from_secs(1));
49
50 let client = Client::new(client_config)?;
51 client.run().await?;
52
53 // Get measurements
54 let measurements = client.get_measurements();
55 let total_bytes = measurements.total_bytes_sent + measurements.total_bytes_received;
56 let bits_per_second = measurements.total_bits_per_second();
57
58 println!("\n=== Results ===");
59 println!(
60 "Total transferred: {:.2} MB",
61 total_bytes as f64 / 1_000_000.0
62 );
63 println!("Throughput: {:.2} Mbps", bits_per_second / 1_000_000.0);
64 println!("\nSocket optimizations applied:");
65 println!("✓ TCP_NODELAY: enabled");
66 println!("✓ Send buffer: 256KB");
67 println!("✓ Recv buffer: 256KB");
68
69 Ok(())
70}20async fn main() -> Result<(), Box<dyn std::error::Error>> {
21 // Initialize logging
22 env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
23
24 println!("UDP Socket Optimization Demo");
25 println!("============================\n");
26 println!("This demo tests UDP with:");
27 println!("- 2MB send/receive buffers");
28 println!("- Improved burst handling");
29 println!("- Expected 10-20% improvement with reduced packet loss\n");
30 println!("Note: Make sure the server is running first:");
31 println!(" cargo run --release -- -s -p 5201\n");
32
33 println!("Starting UDP test (5 seconds, 100 Mbps)...\n");
34
35 // Run client test with bandwidth limiting
36 let client_config = Config::client("127.0.0.1".to_string(), 5201)
37 .with_protocol(Protocol::Udp)
38 .with_duration(Duration::from_secs(5))
39 .with_interval(Duration::from_secs(1))
40 .with_bandwidth(100_000_000); // 100 Mbps
41
42 let client = Client::new(client_config)?;
43 client.run().await?;
44
45 // Get measurements
46 let measurements = client.get_measurements();
47 let total_bytes = measurements.total_bytes_sent + measurements.total_bytes_received;
48 let bits_per_second = measurements.total_bits_per_second();
49 let packet_loss = if measurements.total_packets > 0 {
50 (measurements.lost_packets as f64 / measurements.total_packets as f64) * 100.0
51 } else {
52 0.0
53 };
54
55 println!("\n=== Results ===");
56 println!(
57 "Total transferred: {:.2} MB",
58 total_bytes as f64 / 1_000_000.0
59 );
60 println!("Throughput: {:.2} Mbps", bits_per_second / 1_000_000.0);
61 println!("Packet loss: {:.2}%", packet_loss);
62 println!("\nSocket optimizations applied:");
63 println!("✓ Send buffer: 2MB");
64 println!("✓ Recv buffer: 2MB");
65 println!("✓ Reduced packet loss with larger buffers");
66
67 Ok(())
68}Sourcepub fn with_protocol(self, protocol: Protocol) -> Self
pub fn with_protocol(self, protocol: Protocol) -> Self
Sets the protocol to use for the test.
§Arguments
protocol- EitherProtocol::TcporProtocol::Udp
§Examples
use rperf3::{Config, Protocol};
let config = Config::client("127.0.0.1".to_string(), 5201)
.with_protocol(Protocol::Udp);Examples found in repository?
4async fn main() -> Result<(), Box<dyn std::error::Error>> {
5 env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
6
7 println!("Starting rperf3 server on port 5201...");
8
9 let config = Config::server(5201).with_protocol(Protocol::Tcp);
10
11 let server = Server::new(config);
12 server.run().await?;
13
14 Ok(())
15}More examples
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6 env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
7
8 println!("Connecting to rperf3 server at 127.0.0.1:5201...");
9
10 let config = Config::client("127.0.0.1".to_string(), 5201)
11 .with_protocol(Protocol::Tcp)
12 .with_duration(Duration::from_secs(10))
13 .with_buffer_size(128 * 1024);
14
15 let client = Client::new(config)?;
16 client.run().await?;
17
18 let measurements = client.get_measurements();
19 println!(
20 "\nFinal Results: {:.2} Mbps",
21 measurements.total_bits_per_second() / 1_000_000.0
22 );
23
24 Ok(())
25}5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6 env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
7
8 println!("Running UDP test with 50 Mbps target bandwidth...");
9
10 let config = Config::client("127.0.0.1".to_string(), 5201)
11 .with_protocol(Protocol::Udp)
12 .with_duration(Duration::from_secs(10))
13 .with_bandwidth(50 * 1_000_000) // 50 Mbps
14 .with_buffer_size(1024);
15
16 let client = Client::new(config)?;
17 client.run().await?;
18
19 let measurements = client.get_measurements();
20 println!(
21 "\nFinal Results: {:.2} Mbps",
22 measurements.total_bits_per_second() / 1_000_000.0
23 );
24
25 Ok(())
26}49async fn main() -> Result<(), Box<dyn std::error::Error>> {
50 env_logger::init();
51
52 println!("rperf3 Client with Callback Example");
53 println!("====================================\n");
54
55 // Configure the test
56 let config = Config::client("127.0.0.1".to_string(), 5201)
57 .with_protocol(Protocol::Tcp)
58 .with_duration(Duration::from_secs(10))
59 .with_buffer_size(128 * 1024)
60 .with_interval(Duration::from_secs(2)); // Report every 2 seconds
61
62 // Create client with custom callback
63 let client = Client::new(config)?.with_callback(MyProgressCallback);
64
65 println!("Connecting to server at 127.0.0.1:5201...\n");
66
67 // Run the test (callback will be invoked during execution)
68 client.run().await?;
69
70 // Get final measurements
71 let measurements = client.get_measurements();
72 println!("\n📈 Final Statistics:");
73 println!(" Total bytes: {}", measurements.total_bytes_sent);
74 println!(
75 " Duration: {:.2}s",
76 measurements.total_duration.as_secs_f64()
77 );
78 println!(
79 " Average bandwidth: {:.2} Mbps",
80 measurements.total_bits_per_second() / 1_000_000.0
81 );
82
83 Ok(())
84}17async fn main() -> Result<(), Box<dyn std::error::Error>> {
18 // Initialize logging
19 env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
20
21 println!("TCP Socket Optimization Demo");
22 println!("============================\n");
23 println!("This demo tests TCP with:");
24 println!("- TCP_NODELAY enabled (Nagle's algorithm disabled)");
25 println!("- 256KB send/receive buffers");
26 println!("- Expected 10-20% improvement over default settings\n");
27
28 // Start server in background
29 let server_config = Config::server(5201).with_protocol(Protocol::Tcp);
30 let server = Server::new(server_config);
31
32 // Run server in background task
33 tokio::spawn(async move {
34 if let Err(e) = server.run().await {
35 eprintln!("Server error: {}", e);
36 }
37 });
38
39 // Give server time to start
40 time::sleep(Duration::from_millis(100)).await;
41
42 println!("Starting TCP test (5 seconds)...\n");
43
44 // Run client test
45 let client_config = Config::client("127.0.0.1".to_string(), 5201)
46 .with_protocol(Protocol::Tcp)
47 .with_duration(Duration::from_secs(5))
48 .with_interval(Duration::from_secs(1));
49
50 let client = Client::new(client_config)?;
51 client.run().await?;
52
53 // Get measurements
54 let measurements = client.get_measurements();
55 let total_bytes = measurements.total_bytes_sent + measurements.total_bytes_received;
56 let bits_per_second = measurements.total_bits_per_second();
57
58 println!("\n=== Results ===");
59 println!(
60 "Total transferred: {:.2} MB",
61 total_bytes as f64 / 1_000_000.0
62 );
63 println!("Throughput: {:.2} Mbps", bits_per_second / 1_000_000.0);
64 println!("\nSocket optimizations applied:");
65 println!("✓ TCP_NODELAY: enabled");
66 println!("✓ Send buffer: 256KB");
67 println!("✓ Recv buffer: 256KB");
68
69 Ok(())
70}20async fn main() -> Result<(), Box<dyn std::error::Error>> {
21 // Initialize logging
22 env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
23
24 println!("UDP Socket Optimization Demo");
25 println!("============================\n");
26 println!("This demo tests UDP with:");
27 println!("- 2MB send/receive buffers");
28 println!("- Improved burst handling");
29 println!("- Expected 10-20% improvement with reduced packet loss\n");
30 println!("Note: Make sure the server is running first:");
31 println!(" cargo run --release -- -s -p 5201\n");
32
33 println!("Starting UDP test (5 seconds, 100 Mbps)...\n");
34
35 // Run client test with bandwidth limiting
36 let client_config = Config::client("127.0.0.1".to_string(), 5201)
37 .with_protocol(Protocol::Udp)
38 .with_duration(Duration::from_secs(5))
39 .with_interval(Duration::from_secs(1))
40 .with_bandwidth(100_000_000); // 100 Mbps
41
42 let client = Client::new(client_config)?;
43 client.run().await?;
44
45 // Get measurements
46 let measurements = client.get_measurements();
47 let total_bytes = measurements.total_bytes_sent + measurements.total_bytes_received;
48 let bits_per_second = measurements.total_bits_per_second();
49 let packet_loss = if measurements.total_packets > 0 {
50 (measurements.lost_packets as f64 / measurements.total_packets as f64) * 100.0
51 } else {
52 0.0
53 };
54
55 println!("\n=== Results ===");
56 println!(
57 "Total transferred: {:.2} MB",
58 total_bytes as f64 / 1_000_000.0
59 );
60 println!("Throughput: {:.2} Mbps", bits_per_second / 1_000_000.0);
61 println!("Packet loss: {:.2}%", packet_loss);
62 println!("\nSocket optimizations applied:");
63 println!("✓ Send buffer: 2MB");
64 println!("✓ Recv buffer: 2MB");
65 println!("✓ Reduced packet loss with larger buffers");
66
67 Ok(())
68}Sourcepub fn with_duration(self, duration: Duration) -> Self
pub fn with_duration(self, duration: Duration) -> Self
Sets the test duration.
§Arguments
duration- How long the test should run
§Examples
use rperf3::Config;
use std::time::Duration;
let config = Config::client("127.0.0.1".to_string(), 5201)
.with_duration(Duration::from_secs(30));Examples found in repository?
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6 env_logger::init();
7
8 let config = Config::client("127.0.0.1".to_string(), 5201)
9 .with_duration(Duration::from_secs(3))
10 .with_json(true);
11
12 let client = Client::new(config)?;
13
14 match client.run().await {
15 Ok(_) => println!("\nTest completed successfully"),
16 Err(e) => eprintln!("\nError: {}", e),
17 }
18
19 Ok(())
20}More examples
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6 env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
7
8 println!("Connecting to rperf3 server at 127.0.0.1:5201...");
9
10 let config = Config::client("127.0.0.1".to_string(), 5201)
11 .with_protocol(Protocol::Tcp)
12 .with_duration(Duration::from_secs(10))
13 .with_buffer_size(128 * 1024);
14
15 let client = Client::new(config)?;
16 client.run().await?;
17
18 let measurements = client.get_measurements();
19 println!(
20 "\nFinal Results: {:.2} Mbps",
21 measurements.total_bits_per_second() / 1_000_000.0
22 );
23
24 Ok(())
25}5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6 env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
7
8 println!("Running UDP test with 50 Mbps target bandwidth...");
9
10 let config = Config::client("127.0.0.1".to_string(), 5201)
11 .with_protocol(Protocol::Udp)
12 .with_duration(Duration::from_secs(10))
13 .with_bandwidth(50 * 1_000_000) // 50 Mbps
14 .with_buffer_size(1024);
15
16 let client = Client::new(config)?;
17 client.run().await?;
18
19 let measurements = client.get_measurements();
20 println!(
21 "\nFinal Results: {:.2} Mbps",
22 measurements.total_bits_per_second() / 1_000_000.0
23 );
24
25 Ok(())
26}49async fn main() -> Result<(), Box<dyn std::error::Error>> {
50 env_logger::init();
51
52 println!("rperf3 Client with Callback Example");
53 println!("====================================\n");
54
55 // Configure the test
56 let config = Config::client("127.0.0.1".to_string(), 5201)
57 .with_protocol(Protocol::Tcp)
58 .with_duration(Duration::from_secs(10))
59 .with_buffer_size(128 * 1024)
60 .with_interval(Duration::from_secs(2)); // Report every 2 seconds
61
62 // Create client with custom callback
63 let client = Client::new(config)?.with_callback(MyProgressCallback);
64
65 println!("Connecting to server at 127.0.0.1:5201...\n");
66
67 // Run the test (callback will be invoked during execution)
68 client.run().await?;
69
70 // Get final measurements
71 let measurements = client.get_measurements();
72 println!("\n📈 Final Statistics:");
73 println!(" Total bytes: {}", measurements.total_bytes_sent);
74 println!(
75 " Duration: {:.2}s",
76 measurements.total_duration.as_secs_f64()
77 );
78 println!(
79 " Average bandwidth: {:.2} Mbps",
80 measurements.total_bits_per_second() / 1_000_000.0
81 );
82
83 Ok(())
84}17async fn main() -> Result<(), Box<dyn std::error::Error>> {
18 // Initialize logging
19 env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
20
21 println!("TCP Socket Optimization Demo");
22 println!("============================\n");
23 println!("This demo tests TCP with:");
24 println!("- TCP_NODELAY enabled (Nagle's algorithm disabled)");
25 println!("- 256KB send/receive buffers");
26 println!("- Expected 10-20% improvement over default settings\n");
27
28 // Start server in background
29 let server_config = Config::server(5201).with_protocol(Protocol::Tcp);
30 let server = Server::new(server_config);
31
32 // Run server in background task
33 tokio::spawn(async move {
34 if let Err(e) = server.run().await {
35 eprintln!("Server error: {}", e);
36 }
37 });
38
39 // Give server time to start
40 time::sleep(Duration::from_millis(100)).await;
41
42 println!("Starting TCP test (5 seconds)...\n");
43
44 // Run client test
45 let client_config = Config::client("127.0.0.1".to_string(), 5201)
46 .with_protocol(Protocol::Tcp)
47 .with_duration(Duration::from_secs(5))
48 .with_interval(Duration::from_secs(1));
49
50 let client = Client::new(client_config)?;
51 client.run().await?;
52
53 // Get measurements
54 let measurements = client.get_measurements();
55 let total_bytes = measurements.total_bytes_sent + measurements.total_bytes_received;
56 let bits_per_second = measurements.total_bits_per_second();
57
58 println!("\n=== Results ===");
59 println!(
60 "Total transferred: {:.2} MB",
61 total_bytes as f64 / 1_000_000.0
62 );
63 println!("Throughput: {:.2} Mbps", bits_per_second / 1_000_000.0);
64 println!("\nSocket optimizations applied:");
65 println!("✓ TCP_NODELAY: enabled");
66 println!("✓ Send buffer: 256KB");
67 println!("✓ Recv buffer: 256KB");
68
69 Ok(())
70}20async fn main() -> Result<(), Box<dyn std::error::Error>> {
21 // Initialize logging
22 env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
23
24 println!("UDP Socket Optimization Demo");
25 println!("============================\n");
26 println!("This demo tests UDP with:");
27 println!("- 2MB send/receive buffers");
28 println!("- Improved burst handling");
29 println!("- Expected 10-20% improvement with reduced packet loss\n");
30 println!("Note: Make sure the server is running first:");
31 println!(" cargo run --release -- -s -p 5201\n");
32
33 println!("Starting UDP test (5 seconds, 100 Mbps)...\n");
34
35 // Run client test with bandwidth limiting
36 let client_config = Config::client("127.0.0.1".to_string(), 5201)
37 .with_protocol(Protocol::Udp)
38 .with_duration(Duration::from_secs(5))
39 .with_interval(Duration::from_secs(1))
40 .with_bandwidth(100_000_000); // 100 Mbps
41
42 let client = Client::new(client_config)?;
43 client.run().await?;
44
45 // Get measurements
46 let measurements = client.get_measurements();
47 let total_bytes = measurements.total_bytes_sent + measurements.total_bytes_received;
48 let bits_per_second = measurements.total_bits_per_second();
49 let packet_loss = if measurements.total_packets > 0 {
50 (measurements.lost_packets as f64 / measurements.total_packets as f64) * 100.0
51 } else {
52 0.0
53 };
54
55 println!("\n=== Results ===");
56 println!(
57 "Total transferred: {:.2} MB",
58 total_bytes as f64 / 1_000_000.0
59 );
60 println!("Throughput: {:.2} Mbps", bits_per_second / 1_000_000.0);
61 println!("Packet loss: {:.2}%", packet_loss);
62 println!("\nSocket optimizations applied:");
63 println!("✓ Send buffer: 2MB");
64 println!("✓ Recv buffer: 2MB");
65 println!("✓ Reduced packet loss with larger buffers");
66
67 Ok(())
68}Sourcepub fn with_bandwidth(self, bandwidth: u64) -> Self
pub fn with_bandwidth(self, bandwidth: u64) -> Self
Sets the target bandwidth for tests.
Controls the send rate for both TCP and UDP tests. The bandwidth limiter uses a rate-based algorithm that checks bandwidth every 1ms and sleeps when sending too fast.
§Arguments
bandwidth- Target bandwidth in bits per second
§Examples
use rperf3::{Config, Protocol};
// UDP test at 100 Mbps
let udp_config = Config::client("127.0.0.1".to_string(), 5201)
.with_protocol(Protocol::Udp)
.with_bandwidth(100_000_000); // 100 Mbps
// TCP test at 50 Mbps
let tcp_config = Config::client("127.0.0.1".to_string(), 5201)
.with_protocol(Protocol::Tcp)
.with_bandwidth(50_000_000); // 50 MbpsExamples found in repository?
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6 env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
7
8 println!("Running UDP test with 50 Mbps target bandwidth...");
9
10 let config = Config::client("127.0.0.1".to_string(), 5201)
11 .with_protocol(Protocol::Udp)
12 .with_duration(Duration::from_secs(10))
13 .with_bandwidth(50 * 1_000_000) // 50 Mbps
14 .with_buffer_size(1024);
15
16 let client = Client::new(config)?;
17 client.run().await?;
18
19 let measurements = client.get_measurements();
20 println!(
21 "\nFinal Results: {:.2} Mbps",
22 measurements.total_bits_per_second() / 1_000_000.0
23 );
24
25 Ok(())
26}More examples
20async fn main() -> Result<(), Box<dyn std::error::Error>> {
21 // Initialize logging
22 env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
23
24 println!("UDP Socket Optimization Demo");
25 println!("============================\n");
26 println!("This demo tests UDP with:");
27 println!("- 2MB send/receive buffers");
28 println!("- Improved burst handling");
29 println!("- Expected 10-20% improvement with reduced packet loss\n");
30 println!("Note: Make sure the server is running first:");
31 println!(" cargo run --release -- -s -p 5201\n");
32
33 println!("Starting UDP test (5 seconds, 100 Mbps)...\n");
34
35 // Run client test with bandwidth limiting
36 let client_config = Config::client("127.0.0.1".to_string(), 5201)
37 .with_protocol(Protocol::Udp)
38 .with_duration(Duration::from_secs(5))
39 .with_interval(Duration::from_secs(1))
40 .with_bandwidth(100_000_000); // 100 Mbps
41
42 let client = Client::new(client_config)?;
43 client.run().await?;
44
45 // Get measurements
46 let measurements = client.get_measurements();
47 let total_bytes = measurements.total_bytes_sent + measurements.total_bytes_received;
48 let bits_per_second = measurements.total_bits_per_second();
49 let packet_loss = if measurements.total_packets > 0 {
50 (measurements.lost_packets as f64 / measurements.total_packets as f64) * 100.0
51 } else {
52 0.0
53 };
54
55 println!("\n=== Results ===");
56 println!(
57 "Total transferred: {:.2} MB",
58 total_bytes as f64 / 1_000_000.0
59 );
60 println!("Throughput: {:.2} Mbps", bits_per_second / 1_000_000.0);
61 println!("Packet loss: {:.2}%", packet_loss);
62 println!("\nSocket optimizations applied:");
63 println!("✓ Send buffer: 2MB");
64 println!("✓ Recv buffer: 2MB");
65 println!("✓ Reduced packet loss with larger buffers");
66
67 Ok(())
68}Sourcepub fn with_buffer_size(self, size: usize) -> Self
pub fn with_buffer_size(self, size: usize) -> Self
Sets the buffer size for data transfer.
Larger buffer sizes can improve throughput but use more memory.
§Arguments
size- Buffer size in bytes (default: 128 KB)
§Examples
use rperf3::Config;
let config = Config::client("127.0.0.1".to_string(), 5201)
.with_buffer_size(256 * 1024); // 256 KBExamples found in repository?
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6 env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
7
8 println!("Connecting to rperf3 server at 127.0.0.1:5201...");
9
10 let config = Config::client("127.0.0.1".to_string(), 5201)
11 .with_protocol(Protocol::Tcp)
12 .with_duration(Duration::from_secs(10))
13 .with_buffer_size(128 * 1024);
14
15 let client = Client::new(config)?;
16 client.run().await?;
17
18 let measurements = client.get_measurements();
19 println!(
20 "\nFinal Results: {:.2} Mbps",
21 measurements.total_bits_per_second() / 1_000_000.0
22 );
23
24 Ok(())
25}More examples
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6 env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
7
8 println!("Running UDP test with 50 Mbps target bandwidth...");
9
10 let config = Config::client("127.0.0.1".to_string(), 5201)
11 .with_protocol(Protocol::Udp)
12 .with_duration(Duration::from_secs(10))
13 .with_bandwidth(50 * 1_000_000) // 50 Mbps
14 .with_buffer_size(1024);
15
16 let client = Client::new(config)?;
17 client.run().await?;
18
19 let measurements = client.get_measurements();
20 println!(
21 "\nFinal Results: {:.2} Mbps",
22 measurements.total_bits_per_second() / 1_000_000.0
23 );
24
25 Ok(())
26}49async fn main() -> Result<(), Box<dyn std::error::Error>> {
50 env_logger::init();
51
52 println!("rperf3 Client with Callback Example");
53 println!("====================================\n");
54
55 // Configure the test
56 let config = Config::client("127.0.0.1".to_string(), 5201)
57 .with_protocol(Protocol::Tcp)
58 .with_duration(Duration::from_secs(10))
59 .with_buffer_size(128 * 1024)
60 .with_interval(Duration::from_secs(2)); // Report every 2 seconds
61
62 // Create client with custom callback
63 let client = Client::new(config)?.with_callback(MyProgressCallback);
64
65 println!("Connecting to server at 127.0.0.1:5201...\n");
66
67 // Run the test (callback will be invoked during execution)
68 client.run().await?;
69
70 // Get final measurements
71 let measurements = client.get_measurements();
72 println!("\n📈 Final Statistics:");
73 println!(" Total bytes: {}", measurements.total_bytes_sent);
74 println!(
75 " Duration: {:.2}s",
76 measurements.total_duration.as_secs_f64()
77 );
78 println!(
79 " Average bandwidth: {:.2} Mbps",
80 measurements.total_bits_per_second() / 1_000_000.0
81 );
82
83 Ok(())
84}6async fn main() -> Result<(), Box<dyn std::error::Error>> {
7 env_logger::init();
8
9 println!("rperf3 Client with Closure Callback Example");
10 println!("===========================================\n");
11
12 // Track progress with shared state
13 let progress = Arc::new(Mutex::new(Vec::new()));
14 let progress_clone = Arc::clone(&progress);
15
16 // Configure the test
17 let config = Config::client("127.0.0.1".to_string(), 5201)
18 .with_protocol(Protocol::Tcp)
19 .with_duration(Duration::from_secs(5))
20 .with_buffer_size(128 * 1024)
21 .with_interval(Duration::from_secs(1));
22
23 // Create client with closure callback
24 let client = Client::new(config)?.with_callback(move |event: ProgressEvent| {
25 match &event {
26 ProgressEvent::TestStarted => {
27 println!("✨ Starting test...");
28 }
29 ProgressEvent::IntervalUpdate {
30 interval_end,
31 bytes,
32 bits_per_second,
33 ..
34 } => {
35 let mbps = bits_per_second / 1_000_000.0;
36 println!(
37 "⏱️ {:>5.1}s | {:>10} bytes | {:>8.2} Mbps",
38 interval_end.as_secs_f64(),
39 bytes,
40 mbps
41 );
42
43 // Store progress for later analysis
44 if let Ok(mut prog) = progress_clone.lock() {
45 prog.push((*interval_end, *bytes, *bits_per_second));
46 }
47 }
48 ProgressEvent::TestCompleted {
49 total_bytes,
50 duration,
51 bits_per_second,
52 ..
53 } => {
54 println!("\n🎉 Test finished!");
55 println!(" {} bytes in {:.2}s", total_bytes, duration.as_secs_f64());
56 println!(" Average: {:.2} Mbps", bits_per_second / 1_000_000.0);
57 }
58 ProgressEvent::Error(msg) => {
59 eprintln!("❌ Error: {}", msg);
60 }
61 }
62 });
63
64 println!("Connecting to server at 127.0.0.1:5201...\n");
65
66 // Run the test
67 client.run().await?;
68
69 // Analyze collected progress data
70 if let Ok(prog) = progress.lock() {
71 if !prog.is_empty() {
72 println!("\n📊 Progress Analysis:");
73 let avg_mbps: f64 = prog
74 .iter()
75 .map(|(_, _, bps)| bps / 1_000_000.0)
76 .sum::<f64>()
77 / prog.len() as f64;
78 println!(" Intervals recorded: {}", prog.len());
79 println!(" Average interval speed: {:.2} Mbps", avg_mbps);
80
81 let max_mbps = prog
82 .iter()
83 .map(|(_, _, bps)| bps / 1_000_000.0)
84 .fold(0.0f64, f64::max);
85 let min_mbps = prog
86 .iter()
87 .map(|(_, _, bps)| bps / 1_000_000.0)
88 .fold(f64::INFINITY, f64::min);
89 println!(" Peak speed: {:.2} Mbps", max_mbps);
90 println!(" Lowest speed: {:.2} Mbps", min_mbps);
91 }
92 }
93
94 Ok(())
95}Sourcepub fn with_parallel(self, parallel: usize) -> Self
pub fn with_parallel(self, parallel: usize) -> Self
Sets the number of parallel streams.
Multiple parallel streams can improve throughput by utilizing multiple connections simultaneously. This is particularly useful for high-bandwidth networks where a single stream might not saturate the link.
§Arguments
parallel- Number of parallel streams (default: 1)
§Examples
use rperf3::Config;
let config = Config::client("127.0.0.1".to_string(), 5201)
.with_parallel(4); // Use 4 parallel streamsSourcepub fn with_reverse(self, reverse: bool) -> Self
pub fn with_reverse(self, reverse: bool) -> Self
Enables or disables reverse mode.
In reverse mode, the server sends data and the client receives. In normal mode, the client sends data and the server receives.
§Arguments
reverse-truefor reverse mode,falsefor normal mode
§Examples
use rperf3::Config;
let config = Config::client("127.0.0.1".to_string(), 5201)
.with_reverse(true);Sourcepub fn with_json(self, json: bool) -> Self
pub fn with_json(self, json: bool) -> Self
Enables or disables JSON output format.
When enabled, results are output in machine-readable JSON format similar to iperf3.
§Arguments
json-trueto enable JSON output,falsefor human-readable
§Examples
use rperf3::Config;
let config = Config::client("127.0.0.1".to_string(), 5201)
.with_json(true);Examples found in repository?
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6 env_logger::init();
7
8 let config = Config::client("127.0.0.1".to_string(), 5201)
9 .with_duration(Duration::from_secs(3))
10 .with_json(true);
11
12 let client = Client::new(config)?;
13
14 match client.run().await {
15 Ok(_) => println!("\nTest completed successfully"),
16 Err(e) => eprintln!("\nError: {}", e),
17 }
18
19 Ok(())
20}Sourcepub fn with_interval(self, interval: Duration) -> Self
pub fn with_interval(self, interval: Duration) -> Self
Sets the interval for periodic reporting.
Statistics will be reported at this interval during the test.
§Arguments
interval- How often to report statistics (default: 1 second)
§Examples
use rperf3::Config;
use std::time::Duration;
let config = Config::client("127.0.0.1".to_string(), 5201)
.with_interval(Duration::from_secs(2));Examples found in repository?
49async fn main() -> Result<(), Box<dyn std::error::Error>> {
50 env_logger::init();
51
52 println!("rperf3 Client with Callback Example");
53 println!("====================================\n");
54
55 // Configure the test
56 let config = Config::client("127.0.0.1".to_string(), 5201)
57 .with_protocol(Protocol::Tcp)
58 .with_duration(Duration::from_secs(10))
59 .with_buffer_size(128 * 1024)
60 .with_interval(Duration::from_secs(2)); // Report every 2 seconds
61
62 // Create client with custom callback
63 let client = Client::new(config)?.with_callback(MyProgressCallback);
64
65 println!("Connecting to server at 127.0.0.1:5201...\n");
66
67 // Run the test (callback will be invoked during execution)
68 client.run().await?;
69
70 // Get final measurements
71 let measurements = client.get_measurements();
72 println!("\n📈 Final Statistics:");
73 println!(" Total bytes: {}", measurements.total_bytes_sent);
74 println!(
75 " Duration: {:.2}s",
76 measurements.total_duration.as_secs_f64()
77 );
78 println!(
79 " Average bandwidth: {:.2} Mbps",
80 measurements.total_bits_per_second() / 1_000_000.0
81 );
82
83 Ok(())
84}More examples
17async fn main() -> Result<(), Box<dyn std::error::Error>> {
18 // Initialize logging
19 env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
20
21 println!("TCP Socket Optimization Demo");
22 println!("============================\n");
23 println!("This demo tests TCP with:");
24 println!("- TCP_NODELAY enabled (Nagle's algorithm disabled)");
25 println!("- 256KB send/receive buffers");
26 println!("- Expected 10-20% improvement over default settings\n");
27
28 // Start server in background
29 let server_config = Config::server(5201).with_protocol(Protocol::Tcp);
30 let server = Server::new(server_config);
31
32 // Run server in background task
33 tokio::spawn(async move {
34 if let Err(e) = server.run().await {
35 eprintln!("Server error: {}", e);
36 }
37 });
38
39 // Give server time to start
40 time::sleep(Duration::from_millis(100)).await;
41
42 println!("Starting TCP test (5 seconds)...\n");
43
44 // Run client test
45 let client_config = Config::client("127.0.0.1".to_string(), 5201)
46 .with_protocol(Protocol::Tcp)
47 .with_duration(Duration::from_secs(5))
48 .with_interval(Duration::from_secs(1));
49
50 let client = Client::new(client_config)?;
51 client.run().await?;
52
53 // Get measurements
54 let measurements = client.get_measurements();
55 let total_bytes = measurements.total_bytes_sent + measurements.total_bytes_received;
56 let bits_per_second = measurements.total_bits_per_second();
57
58 println!("\n=== Results ===");
59 println!(
60 "Total transferred: {:.2} MB",
61 total_bytes as f64 / 1_000_000.0
62 );
63 println!("Throughput: {:.2} Mbps", bits_per_second / 1_000_000.0);
64 println!("\nSocket optimizations applied:");
65 println!("✓ TCP_NODELAY: enabled");
66 println!("✓ Send buffer: 256KB");
67 println!("✓ Recv buffer: 256KB");
68
69 Ok(())
70}20async fn main() -> Result<(), Box<dyn std::error::Error>> {
21 // Initialize logging
22 env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
23
24 println!("UDP Socket Optimization Demo");
25 println!("============================\n");
26 println!("This demo tests UDP with:");
27 println!("- 2MB send/receive buffers");
28 println!("- Improved burst handling");
29 println!("- Expected 10-20% improvement with reduced packet loss\n");
30 println!("Note: Make sure the server is running first:");
31 println!(" cargo run --release -- -s -p 5201\n");
32
33 println!("Starting UDP test (5 seconds, 100 Mbps)...\n");
34
35 // Run client test with bandwidth limiting
36 let client_config = Config::client("127.0.0.1".to_string(), 5201)
37 .with_protocol(Protocol::Udp)
38 .with_duration(Duration::from_secs(5))
39 .with_interval(Duration::from_secs(1))
40 .with_bandwidth(100_000_000); // 100 Mbps
41
42 let client = Client::new(client_config)?;
43 client.run().await?;
44
45 // Get measurements
46 let measurements = client.get_measurements();
47 let total_bytes = measurements.total_bytes_sent + measurements.total_bytes_received;
48 let bits_per_second = measurements.total_bits_per_second();
49 let packet_loss = if measurements.total_packets > 0 {
50 (measurements.lost_packets as f64 / measurements.total_packets as f64) * 100.0
51 } else {
52 0.0
53 };
54
55 println!("\n=== Results ===");
56 println!(
57 "Total transferred: {:.2} MB",
58 total_bytes as f64 / 1_000_000.0
59 );
60 println!("Throughput: {:.2} Mbps", bits_per_second / 1_000_000.0);
61 println!("Packet loss: {:.2}%", packet_loss);
62 println!("\nSocket optimizations applied:");
63 println!("✓ Send buffer: 2MB");
64 println!("✓ Recv buffer: 2MB");
65 println!("✓ Reduced packet loss with larger buffers");
66
67 Ok(())
68}6async fn main() -> Result<(), Box<dyn std::error::Error>> {
7 env_logger::init();
8
9 println!("rperf3 Client with Closure Callback Example");
10 println!("===========================================\n");
11
12 // Track progress with shared state
13 let progress = Arc::new(Mutex::new(Vec::new()));
14 let progress_clone = Arc::clone(&progress);
15
16 // Configure the test
17 let config = Config::client("127.0.0.1".to_string(), 5201)
18 .with_protocol(Protocol::Tcp)
19 .with_duration(Duration::from_secs(5))
20 .with_buffer_size(128 * 1024)
21 .with_interval(Duration::from_secs(1));
22
23 // Create client with closure callback
24 let client = Client::new(config)?.with_callback(move |event: ProgressEvent| {
25 match &event {
26 ProgressEvent::TestStarted => {
27 println!("✨ Starting test...");
28 }
29 ProgressEvent::IntervalUpdate {
30 interval_end,
31 bytes,
32 bits_per_second,
33 ..
34 } => {
35 let mbps = bits_per_second / 1_000_000.0;
36 println!(
37 "⏱️ {:>5.1}s | {:>10} bytes | {:>8.2} Mbps",
38 interval_end.as_secs_f64(),
39 bytes,
40 mbps
41 );
42
43 // Store progress for later analysis
44 if let Ok(mut prog) = progress_clone.lock() {
45 prog.push((*interval_end, *bytes, *bits_per_second));
46 }
47 }
48 ProgressEvent::TestCompleted {
49 total_bytes,
50 duration,
51 bits_per_second,
52 ..
53 } => {
54 println!("\n🎉 Test finished!");
55 println!(" {} bytes in {:.2}s", total_bytes, duration.as_secs_f64());
56 println!(" Average: {:.2} Mbps", bits_per_second / 1_000_000.0);
57 }
58 ProgressEvent::Error(msg) => {
59 eprintln!("❌ Error: {}", msg);
60 }
61 }
62 });
63
64 println!("Connecting to server at 127.0.0.1:5201...\n");
65
66 // Run the test
67 client.run().await?;
68
69 // Analyze collected progress data
70 if let Ok(prog) = progress.lock() {
71 if !prog.is_empty() {
72 println!("\n📊 Progress Analysis:");
73 let avg_mbps: f64 = prog
74 .iter()
75 .map(|(_, _, bps)| bps / 1_000_000.0)
76 .sum::<f64>()
77 / prog.len() as f64;
78 println!(" Intervals recorded: {}", prog.len());
79 println!(" Average interval speed: {:.2} Mbps", avg_mbps);
80
81 let max_mbps = prog
82 .iter()
83 .map(|(_, _, bps)| bps / 1_000_000.0)
84 .fold(0.0f64, f64::max);
85 let min_mbps = prog
86 .iter()
87 .map(|(_, _, bps)| bps / 1_000_000.0)
88 .fold(f64::INFINITY, f64::min);
89 println!(" Peak speed: {:.2} Mbps", max_mbps);
90 println!(" Lowest speed: {:.2} Mbps", min_mbps);
91 }
92 }
93
94 Ok(())
95}Trait Implementations§
Source§impl<'de> Deserialize<'de> for Config
impl<'de> Deserialize<'de> for Config
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnwindSafe for Config
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)