Skip to content

Commit ba82145

Browse files
committed
v1.3.4: support test warmup and cooldown
1) Refactor the code and move test management to "throughputmanager". 2) Change some variable names to make them fit for the new test stages (warmup, duration, cooldown)
1 parent f761abd commit ba82145

File tree

11 files changed

+256
-160
lines changed

11 files changed

+256
-160
lines changed

src/const.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// ----------------------------------------------------------------------------------
66

77
#define TOOL_NAME "NTTTCP for Linux"
8-
#define TOOL_VERSION "1.3.3"
8+
#define TOOL_VERSION "1.3.4"
99
#define AUTHOR_NAME "Shihua (Simon) Xiao, [email protected]"
1010

1111
#define TCP SOCK_STREAM

src/endpointsync.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,11 @@ int query_receiver_busy_state(int sockfd)
142142
return 0; //server is not busy
143143
}
144144

145-
/* negotiate a test duration time with receiver. if receiver returns:
145+
/* negotiate the total_test_time (warmup + test_duration + coldown) with receiver. if receiver returns:
146146
* -1: indicates error;
147-
* Non-Zero positive integer: negotiated test duration, returned from receiver;
147+
* Non-Zero positive integer: negotiated total_test_time, returned from receiver;
148148
*/
149-
int negotiate_test_duration(int sockfd, int proposed_time)
149+
int negotiate_test_cycle_time(int sockfd, int proposed_time)
150150
{
151151
int converted = htonl(proposed_time);
152152
int response = 0; //the int to be received
@@ -428,33 +428,33 @@ void *create_receiver_sync_socket( void *ptr )
428428
* all sender clients use the test duration specified by receiver.
429429
*/
430430
answer_to_send = tep->test->duration;
431-
tep->confirmed_duration = answer_to_send;
431+
tep->negotiated_test_cycle_time = answer_to_send;
432432
} else if (converted == 0) {
433433
/* the sender request to run with "continuous_mode" (duration == 0),
434434
* receiver then will accept that mode.
435435
*/
436436
if (tep->test->duration !=0)
437437
PRINT_INFO("test is negotiated to run with continuous mode");
438438
answer_to_send = 0;
439-
tep->confirmed_duration = 0;
439+
tep->negotiated_test_cycle_time = 0;
440440
} else {
441441
/* if receiver is specified to run with "continuous_mode", then tell sender to do so;
442442
* else, compare and use the max time as negotiated test duration time
443443
*/
444444
if (tep->test->duration == 0) {
445445
//then tell sender to run with "continuous_mode" too
446446
answer_to_send = 0;
447-
tep->confirmed_duration = 0;
447+
tep->negotiated_test_cycle_time = 0;
448448
} else if (tep->test->duration < converted) {
449449
answer_to_send = converted;
450-
tep->confirmed_duration = answer_to_send;
450+
tep->negotiated_test_cycle_time = answer_to_send;
451451

452-
ASPRINTF(&log, "test duration negotiated is: %d seconds", answer_to_send);
452+
ASPRINTF(&log, "Test cycle time negotiated is: %d seconds", answer_to_send);
453453
PRINT_INFO_FREE(log);
454454
}
455455
else {
456456
answer_to_send = tep->test->duration;
457-
tep->confirmed_duration = answer_to_send;
457+
tep->negotiated_test_cycle_time = answer_to_send;
458458
}
459459
}
460460
}

src/endpointsync.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
int create_sender_sync_socket( struct ntttcp_test_endpoint *tep );
1414
void tell_receiver_test_exit(int sockfd);
1515
int query_receiver_busy_state(int sockfd);
16-
int negotiate_test_duration(int sockfd, int proposed_time);
16+
int negotiate_test_cycle_time(int sockfd, int proposed_time);
1717
int request_to_start(int sockfd, int request);
1818

1919
/* receiver side sync functions */

src/main.c

Lines changed: 19 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/ntttcp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ struct ntttcp_test_endpoint *new_ntttcp_test_endpoint(struct ntttcp_test *test,
6767
e->test = test;
6868
e->state = TEST_NOT_STARTED;
6969
e->receiver_exit_after_done = test->exit_after_done;
70-
e->confirmed_duration = test->duration;
70+
e->negotiated_test_cycle_time = test->warmup + test->duration + test->cooldown;
7171
e->start_time = now;
7272
e->end_time = now;
7373
e->synch_socket = 0;

src/ntttcp.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,20 @@ struct ntttcp_test_endpoint{
5656
int endpoint_role; /* sender or receiver role */
5757
struct ntttcp_test *test;
5858
int state; /* test state */
59-
int confirmed_duration; /* test duration exchanged and confirmed by both sides */
59+
int negotiated_test_cycle_time; /* test cycle time (warmup + duration + cooldown) exchanged and confirmed by both sides */
6060
struct timeval start_time; /* timestamp of test started on this endpoint */
6161
struct timeval end_time; /* timestamp of test ended on this endpoint */
6262
int synch_socket; /* the synch channel for sender/receiver sync */
63-
unsigned int total_threads; /* total threads, including synch thread */
64-
bool receiver_exit_after_done; /* the receiver will exit after test done, or not */
63+
unsigned int total_threads; /* total threads, including synch thread */
64+
bool receiver_exit_after_done; /* the receiver will exit after test done, or not */
6565

66-
struct ntttcp_stream_client **client_streams; /* alloc memory for this if client/sender role */
67-
struct ntttcp_stream_server **server_streams; /* alloc memory for this if server/receiver role */
66+
struct ntttcp_stream_client **client_streams; /* alloc memory for this if client/sender role */
67+
struct ntttcp_stream_server **server_streams; /* alloc memory for this if server/receiver role */
68+
pthread_t *threads; /* linux threads created to transfer test data */
69+
pthread_t *throughput_mgmt_thread; /* linux thread created to manage the throughput on endpoint */
6870

69-
pthread_t *threads; /* linux threads created to transfer test data */
7071
struct ntttcp_test_endpoint_results *results; /* test results */
7172

72-
pthread_t *throughput_mgmt_thread; /* linux thread created to manage the throughput on endpoint */
73-
7473
/* to support testing with multiple senders */
7574
int num_remote_endpoints; /* number to test client/sender endpoints */
7675
int remote_endpoints[MAX_REMOTE_ENDPOINTS]; /* list of the TCP listeners of those endpoints */

src/tcpstream.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ void *run_ntttcp_sender_tcp_stream( void *ptr )
211211

212212
if (total_sub_conn_created == 0)
213213
goto CLEANUP;
214+
sc->num_conns_created = total_sub_conn_created;
214215

215216
/* wait for sync thread to finish */
216217
wait_light_on();
@@ -237,7 +238,6 @@ void *run_ntttcp_sender_tcp_stream( void *ptr )
237238
sc->total_bytes_transferred += n;
238239
}
239240
}
240-
sc->num_conns_created = total_sub_conn_created;
241241
free(buffer);
242242

243243
CLEANUP:

0 commit comments

Comments
 (0)