@@ -16,13 +16,10 @@ int run_ntttcp_sender(struct ntttcp_test_endpoint *tep)
1616 char * log = NULL ;
1717
1818 pthread_attr_t pth_attrs ;
19- uint n , t , threads_created = 0 , total_conns_created = 0 ;
19+ uint n , t , threads_created = 0 ;
2020 struct ntttcp_stream_client * cs ;
2121 int rc , reply_received ;
22- uint64_t nbytes = 0 , total_bytes = 0 ;
2322 void * p_retval ;
24- struct timeval now ;
25- double actual_test_time = 0 ;
2623
2724 if (test -> no_synch == false ) {
2825 /* Negotiate with receiver on:
@@ -46,21 +43,22 @@ int run_ntttcp_sender(struct ntttcp_test_endpoint *tep)
4643 return ERROR_GENERAL ;
4744 }
4845
49- reply_received = negotiate_test_duration (tep -> synch_socket , test -> duration );
46+ reply_received = negotiate_test_cycle_time (tep -> synch_socket ,
47+ test -> warmup + test -> duration + test -> cooldown );
5048 if (reply_received == -1 ) {
51- PRINT_ERR ("sender: failed to negotiate test duration with receiver" );
49+ PRINT_ERR ("sender: failed to negotiate test cycle time with receiver" );
5250 return ERROR_GENERAL ;
5351 }
5452 if (reply_received != test -> duration ) {
5553 if (reply_received == 0 ) {
5654 PRINT_INFO ("test is negotiated to run with continuous mode" );
5755 set_ntttcp_test_endpoint_test_continuous (tep );
5856 } else {
59- ASPRINTF (& log , "test duration negotiated is: %d seconds" , reply_received );
57+ ASPRINTF (& log , "Test cycle time negotiated is: %d seconds" , reply_received );
6058 PRINT_INFO_FREE (log );
6159 }
6260 }
63- tep -> confirmed_duration = reply_received ;
61+ tep -> negotiated_test_cycle_time = reply_received ;
6462
6563 reply_received = request_to_start (tep -> synch_socket ,
6664 tep -> test -> last_client ? (int )'L' : (int )'R' );
@@ -142,73 +140,22 @@ int run_ntttcp_sender(struct ntttcp_test_endpoint *tep)
142140 turn_on_light ();
143141
144142 /* in the case of running in continuous_mode */
145- if (tep -> confirmed_duration == 0 ) {
143+ if (tep -> negotiated_test_cycle_time == 0 ) {
146144 sleep (UINT_MAX );
147- /* either sleep has elapsed, or sleep was interrupted by a signal */
145+ /* either sleep has elapsed, or sleep was interrupted by a signal */
148146 return err_code ;
149147 }
150148
151- get_cpu_usage ( tep -> results -> init_cpu_usage );
152- get_cpu_usage_from_proc_stat ( tep -> results -> init_cpu_ps );
153- get_tcp_retrans ( tep -> results -> init_tcp_retrans );
154-
155- /* run the timer. it will trigger turn_off_light() after timer timeout */
156- run_test_timer (tep -> confirmed_duration );
157- tep -> state = TEST_RUNNING ;
158- gettimeofday (& now , NULL );
159- tep -> start_time = now ;
160-
161- /* wait test done */
149+ /* wait for test done (after the timer fired, or CTRL+C) */
162150 wait_light_off ();
163151
164- tep -> state = TEST_FINISHED ;
165- gettimeofday (& now , NULL );
166- tep -> end_time = now ;
167-
168- /* calculate the actual test run time */
169- actual_test_time = get_time_diff (& tep -> end_time , & tep -> start_time );
170-
171- /*
172- * if actual_test_time < tep->confirmed_duration;
173- * then this indicates that in the sender side, test is being interrupted.
174- * hence, tell receiver about this.
175- */
176- if (actual_test_time < tep -> confirmed_duration ) {
177- tell_receiver_test_exit (tep -> synch_socket );
178- }
179- close (tep -> synch_socket );
180-
181- /* calculate resource usage */
182- get_cpu_usage ( tep -> results -> final_cpu_usage );
183- get_cpu_usage_from_proc_stat ( tep -> results -> final_cpu_ps );
184- get_tcp_retrans ( tep -> results -> final_tcp_retrans );
185-
186- /* calculate client side throughput, but exclude the last thread as it is synch thread */
187152 for (n = 0 ; n < threads_created ; n ++ ) {
188153 if (pthread_join (tep -> threads [n ], & p_retval ) != 0 ) {
189154 PRINT_ERR ("sender: error when pthread_join" );
190155 continue ;
191156 }
192- total_conns_created += tep -> client_streams [n ]-> num_conns_created ;
193- nbytes = tep -> client_streams [n ]-> total_bytes_transferred ;
194- total_bytes += nbytes ;
195-
196- tep -> results -> threads [n ]-> total_bytes = nbytes ;
197- tep -> results -> threads [n ]-> actual_test_time = actual_test_time ;
198157 }
199-
200158 pthread_join (* (tep -> throughput_mgmt_thread ), & p_retval );
201- ASPRINTF (& log , "%d connections tested" , total_conns_created );
202- PRINT_INFO_FREE (log );
203-
204- tep -> results -> total_bytes = total_bytes ;
205- tep -> results -> actual_test_time = actual_test_time ;
206-
207- process_test_results (tep );
208- print_test_results (tep );
209- if (tep -> test -> save_xml_log )
210- if (write_result_into_log_file (tep ))
211- PRINT_ERR ("Error writing log to xml file" );
212159
213160 return err_code ;
214161}
@@ -222,9 +169,6 @@ int run_ntttcp_receiver(struct ntttcp_test_endpoint *tep)
222169 uint t , threads_created = 0 ;
223170 struct ntttcp_stream_server * ss ;
224171 int rc ;
225- uint64_t nbytes = 0 , total_bytes = 0 ;
226- struct timeval now ;
227- double actual_test_time = 0 ;
228172
229173 /* create throughput management thread */
230174 rc = pthread_create (tep -> throughput_mgmt_thread ,
@@ -320,69 +264,29 @@ int run_ntttcp_receiver(struct ntttcp_test_endpoint *tep)
320264 (uint64_t )__sync_lock_test_and_set (& (tep -> server_streams [t ]-> total_bytes_transferred ), 0 );
321265
322266 /* in the case of running in continuous_mode */
323- if (tep -> confirmed_duration == 0 ) {
267+ if (tep -> negotiated_test_cycle_time == 0 ) {
324268 sleep (UINT_MAX );
325- /* either sleep has elapsed, or sleep was interrupted by a signal */
269+ /* either sleep has elapsed, or sleep was interrupted by a signal */
326270 return err_code ;
327271 }
328272
329- get_cpu_usage ( tep -> results -> init_cpu_usage );
330- get_cpu_usage_from_proc_stat ( tep -> results -> init_cpu_ps );
331- get_tcp_retrans ( tep -> results -> init_tcp_retrans );
332-
333- /* run the timer. it will trigger turn_off_light() after timer timeout */
334- run_test_timer (tep -> confirmed_duration );
335- tep -> state = TEST_RUNNING ;
336- gettimeofday (& now , NULL );
337- tep -> start_time = now ;
338-
339273 /* wait test done */
340274 wait_light_off ();
341- tep -> state = TEST_FINISHED ;
342- tep -> num_remote_endpoints = 0 ;
343- for (t = 0 ; t < MAX_REMOTE_ENDPOINTS ; t ++ ) tep -> remote_endpoints [t ] = -1 ;
344- gettimeofday (& now , NULL );
345- tep -> end_time = now ;
346-
347- /* calculate the actual test run time */
348- actual_test_time = get_time_diff (& tep -> end_time , & tep -> start_time );
349-
350- /* calculate resource usage */
351- get_cpu_usage ( tep -> results -> final_cpu_usage );
352- get_cpu_usage_from_proc_stat ( tep -> results -> final_cpu_ps );
353- get_tcp_retrans ( tep -> results -> final_tcp_retrans );
354-
355- //sleep(1); //looks like server needs more time to receive data ...
356-
357- /* calculate server side throughput */
358- total_bytes = 0 ;
359- for (t = 0 ; t < threads_created ; t ++ ){
360- /* exclude the sync thread */
361- if (tep -> server_streams [t ]-> is_sync_thread == true)
362- continue ;
363-
364- /* read and reset the counter */
365- nbytes = (uint64_t )__sync_lock_test_and_set (& (tep -> server_streams [t ]-> total_bytes_transferred ), 0 );
366- total_bytes += nbytes ;
367-
368- tep -> results -> threads [t ]-> total_bytes = nbytes ;
369- tep -> results -> threads [t ]-> actual_test_time = actual_test_time ;
370- }
371- tep -> results -> total_bytes = total_bytes ;
372- tep -> results -> actual_test_time = actual_test_time ;
373275
374- process_test_results (tep );
375- print_test_results (tep );
376- if (tep -> test -> save_xml_log )
377- if (write_result_into_log_file (tep ))
378- PRINT_ERR ("Error writing log to xml file" );
276+ /* reset thiss variable, in case receiver is running as '-H' (receiver is running in loop) */
277+ tep -> num_remote_endpoints = 0 ;
278+ for (t = 0 ; t < MAX_REMOTE_ENDPOINTS ; t ++ )
279+ tep -> remote_endpoints [t ] = -1 ;
379280
380281 if (tep -> receiver_exit_after_done )
381282 break ;
382283 }
383284
384285 for (t = 0 ; t < threads_created ; t ++ ) {
385- pthread_join (tep -> threads [t ], NULL );
286+ if (pthread_join (tep -> threads [t ], NULL ) != 0 ) {
287+ PRINT_ERR ("receiver: error when pthread_join" );
288+ continue ;
289+ }
386290 }
387291 pthread_join (* (tep -> throughput_mgmt_thread ), NULL );
388292
0 commit comments