11#![ cfg_attr( coverage_nightly, feature( coverage_attribute) ) ]
2+ use bluefin:: { net:: server:: BluefinServer , utils:: common:: BluefinResult } ;
23use std:: {
34 cmp:: { max, min} ,
45 net:: { Ipv4Addr , SocketAddrV4 } ,
56 time:: Instant ,
67} ;
7-
8- use bluefin:: { net:: server:: BluefinServer , utils:: common:: BluefinResult } ;
98use tokio:: { spawn, task:: JoinSet } ;
109
1110#[ cfg_attr( coverage_nightly, coverage( off) ) ]
@@ -24,68 +23,93 @@ async fn run() -> BluefinResult<()> {
2423 Ipv4Addr :: new ( 127 , 0 , 0 , 1 ) ,
2524 1318 ,
2625 ) ) ) ;
27- server. set_num_reader_workers ( 300 ) ?;
26+ server. set_num_reader_workers ( 3 ) ?;
2827 server. bind ( ) . await ?;
2928 let mut join_set = JoinSet :: new ( ) ;
3029
31- const MAX_NUM_CONNECTIONS : usize = 2 ;
32- for conn_num in 0 ..MAX_NUM_CONNECTIONS {
33- let mut s = server. clone ( ) ;
34- let _num = conn_num;
30+ let mut _num = 0 ;
31+ while let Ok ( mut conn) = server. accept ( ) . await {
3532 let _ = join_set. spawn ( async move {
36- let _conn = s. accept ( ) . await ;
37-
38- match _conn {
39- Ok ( mut conn) => {
4033 let mut total_bytes = 0 ;
41- let mut recv_bytes = [ 0u8 ; 80000 ] ;
34+ let mut recv_bytes = [ 0u8 ; 10000 ] ;
4235 let mut min_bytes = usize:: MAX ;
4336 let mut max_bytes = 0 ;
44- let mut iteration = 1 ;
37+ let mut iteration: i64 = 1 ;
4538 let mut num_iterations_without_print = 0 ;
39+ let mut max_throughput = 0.0 ;
40+ let mut min_throughput = f64:: MAX ;
4641 let now = Instant :: now ( ) ;
4742 loop {
48- let size = conn. recv ( & mut recv_bytes, 80000 ) . await . unwrap ( ) ;
43+ let size = conn. recv ( & mut recv_bytes, 10000 ) . await . unwrap ( ) ;
4944 total_bytes += size;
5045 min_bytes = min ( size, min_bytes) ;
5146 max_bytes = max ( size, max_bytes) ;
5247 // eprintln!("read {} bytes --- total bytes: {}", size, total_bytes);
5348
5449 /*
5550 println!(
56- "({:x}_{:x}) >>> Received: {:?} (total: {}) ",
51+ "({:x}_{:x}) >>> Received: {} bytes ",
5752 conn.src_conn_id,
5853 conn.dst_conn_id,
59- &recv_bytes[..size],
6054 total_bytes
6155 );
6256 */
6357 num_iterations_without_print += 1 ;
64- if total_bytes >= 100000 && num_iterations_without_print == 200 {
58+ if total_bytes >= 1000000 && num_iterations_without_print == 3500 {
6559 let elapsed = now. elapsed ( ) . as_secs ( ) ;
60+ if elapsed == 0 {
61+ eprintln ! ( "(#{})Total bytes: {} (0s???)" , _num, total_bytes) ;
62+ num_iterations_without_print = 0 ;
63+ continue ;
64+ }
6665 let through_put = u64:: try_from ( total_bytes) . unwrap ( ) / elapsed;
66+ let through_put_mb = through_put as f64 / 1e6 ;
6767 let avg_recv_bytes: f64 = total_bytes as f64 / iteration as f64 ;
68- eprintln ! (
69- "{} {:.1} kb/s or {:.1} mb/s (read {:.1} kb/iteration, min: {:.1} kb, max: {:.1} kb)" ,
68+
69+ if through_put_mb > max_throughput {
70+ max_throughput = through_put_mb;
71+ }
72+
73+ if through_put_mb < min_throughput {
74+ min_throughput = through_put_mb;
75+ }
76+
77+ if through_put_mb < 1000.0 {
78+ eprintln ! (
79+ "{} {:.1} kb/s or {:.1} mb/s (read {:.1} kb/iteration, min: {:.1} kb, max: {:.1} kb) (max {:.1} mb/s, min {:.1} mb/s)" ,
7080 _num,
7181 through_put as f64 / 1e3 ,
72- through_put as f64 / 1e6 ,
82+ through_put_mb ,
7383 avg_recv_bytes / 1e3 ,
7484 min_bytes as f64 / 1e3 ,
75- max_bytes as f64 / 1e3
85+ max_bytes as f64 / 1e3 ,
86+ max_throughput,
87+ min_throughput
7688 ) ;
77- num_iterations_without_print = 0 ;
89+ } else {
90+ eprintln ! (
91+ "{} {:.2} gb/s (read {:.1} kb/iter, min: {:.1} kb, max: {:.1} kb) (max {:.2} gb/s, min {:.1} kb/s)" ,
92+ _num,
93+ through_put_mb / 1e3 ,
94+ avg_recv_bytes / 1e3 ,
95+ min_bytes as f64 / 1e3 ,
96+ max_bytes as f64 / 1e3 ,
97+ max_throughput / 1e3 ,
98+ min_throughput
99+ ) ;
100+ }
101+ num_iterations_without_print = 0 ;
78102 // break;
79103 }
80104 iteration += 1 ;
81105 }
82- }
83- Err ( e) => {
84- eprintln ! ( "Could not accept connection due to error: {:?}" , e) ;
85- }
86- }
87106 } ) ;
107+ _num += 1 ;
108+ if _num >= 2 {
109+ break ;
110+ }
88111 }
112+
89113 join_set. join_all ( ) . await ;
90114 Ok ( ( ) )
91115}
0 commit comments