Skip to content

Commit 647a800

Browse files
committed
ntttcp-for-linux 1.3.3: add real-time throughput display
1) on both sender and receiver endpoints, added new thread to manage the throughput (collect "number of bytes transferred" periodically and calculate the real-time throughput) 2) updated tcpstream and udpstream streams to make them report "number of bytes transferred" to its data structure so that the throughtput_management thread cal collect that number from those test streams.
1 parent affde3c commit 647a800

File tree

10 files changed

+97
-13
lines changed

10 files changed

+97
-13
lines changed

src/Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ CC=gcc
22
CFLAGS=-Wall -W -O2 -fno-strict-aliasing
33
CLIBS=-pthread
44
OUT=ntttcp
5-
OBJS=ntttcp.o util.o tcpstream.o udpstream.o endpointsync.o multithreading.o main.o
5+
OBJS=ntttcp.o util.o throughputmanagement.o tcpstream.o udpstream.o endpointsync.o multithreading.o main.o
66

7-
$(OUT): ntttcp.o util.o tcpstream.o udpstream.o endpointsync.o multithreading.o main.o
7+
$(OUT): ntttcp.o util.o throughputmanagement.o tcpstream.o udpstream.o endpointsync.o multithreading.o main.o
88
$(CC) $(CFLAGS) $(CLIBS) -o $(OUT) $(OBJS)
99
ntttcp.o: ntttcp.c
1010
$(CC) $(CFLAGS) -c ntttcp.c -o ntttcp.o
1111
util.o: util.c
1212
$(CC) $(CFLAGS) -c util.c -o util.o
13+
throughputmanagement.o: throughputmanagement.c
14+
$(CC) $(CFLAGS) -c throughputmanagement.c -o throughputmanagement.o
1315
tcpstream.o: tcpstream.c
1416
$(CC) $(CFLAGS) -c tcpstream.c -o tcpstream.o
1517
udpstream.o:udpstream.c

src/const.h

Lines changed: 1 addition & 2 deletions
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.2"
8+
#define TOOL_VERSION "1.3.3"
99
#define AUTHOR_NAME "Shihua (Simon) Xiao, [email protected]"
1010

1111
#define TCP SOCK_STREAM
@@ -19,7 +19,6 @@
1919
#define TEST_RUNNING 12
2020
#define TEST_FINISHED 13
2121

22-
2322
/*
2423
* NUM_SERVER_PORTS: how many PORTs opened by receiver;
2524
* CONNS_PER_SERVER_PORT: how many THREADs on sender side will be created for each receiver PORT;

src/main.c

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,23 @@ int run_ntttcp_sender(struct ntttcp_test_endpoint *tep)
8080
PRINT_INFO("Starting sender activity (no sync) ...");
8181
}
8282

83-
/* create threads */
83+
/* prepare to create threads */
8484
pthread_attr_init(&pth_attrs);
8585
pthread_attr_setstacksize(&pth_attrs, THREAD_STACK_SIZE);
8686

87+
/* create throughput management thread */
88+
rc = pthread_create(tep->throughput_mgmt_thread,
89+
&pth_attrs,
90+
run_ntttcp_throughput_management,
91+
(void*)tep);
92+
if (rc) {
93+
ASPRINTF(&log, "pthread_create(): failed to create throughput management thread. errno = %d", errno);
94+
PRINT_ERR_FREE(log);
95+
pthread_attr_destroy(&pth_attrs);
96+
return ERROR_PTHREAD_CREATE;
97+
}
98+
99+
/* create test threads */
87100
for (t = 0; t < test->server_ports; t++) {
88101
for (n = 0; n < test->threads_per_server_port; n++ ) {
89102
cs = tep->client_streams[t * test->threads_per_server_port + n];
@@ -183,6 +196,8 @@ int run_ntttcp_sender(struct ntttcp_test_endpoint *tep)
183196
tep->results->threads[n]->total_bytes = nbytes;
184197
tep->results->threads[n]->actual_test_time = actual_test_time;
185198
}
199+
200+
pthread_join(*(tep->throughput_mgmt_thread), &p_retval);
186201
ASPRINTF(&log, "%d connections tested", total_conns_created);
187202
PRINT_INFO_FREE(log);
188203

@@ -211,7 +226,18 @@ int run_ntttcp_receiver(struct ntttcp_test_endpoint *tep)
211226
struct timeval now;
212227
double actual_test_time = 0;
213228

214-
/* create threads */
229+
/* create throughput management thread */
230+
rc = pthread_create(tep->throughput_mgmt_thread,
231+
NULL,
232+
run_ntttcp_throughput_management,
233+
(void*)tep);
234+
if (rc) {
235+
ASPRINTF(&log, "pthread_create(): failed to create throughput management thread. errno = %d", errno);
236+
PRINT_ERR_FREE(log);
237+
return ERROR_PTHREAD_CREATE;
238+
}
239+
240+
/* create test threads */
215241
for (t = 0; t < test->server_ports; t++) {
216242
ss = tep->server_streams[t];
217243
ss->server_port = test->server_base_port + t;
@@ -358,6 +384,7 @@ int run_ntttcp_receiver(struct ntttcp_test_endpoint *tep)
358384
for (t=0; t < threads_created; t++) {
359385
pthread_join(tep->threads[t], NULL);
360386
}
387+
pthread_join(*(tep->throughput_mgmt_thread), NULL);
361388

362389
return err_code;
363390
}

src/main.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
#include <stdio.h>
99
#include <limits.h>
1010
#include "endpointsync.h"
11+
#include "throughputmanagement.h"
1112
#include "udpstream.h"

src/ntttcp.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ struct ntttcp_test_endpoint *new_ntttcp_test_endpoint(struct ntttcp_test *test,
127127
return NULL;
128128
}
129129
}
130+
/* for throughput management thread */
131+
e->throughput_mgmt_thread = malloc( sizeof(pthread_t) );
130132

131133
/* for test results */
132134
e->results = (struct ntttcp_test_endpoint_results *) malloc(sizeof(struct ntttcp_test_endpoint_results));
@@ -216,6 +218,7 @@ void free_ntttcp_test_endpoint_and_test(struct ntttcp_test_endpoint* e)
216218
free( e->results->final_tcp_retrans);
217219
free( e->results );
218220
free( e->threads );
221+
free( e->throughput_mgmt_thread );
219222
free( e->test );
220223
free( e );
221224
}

src/ntttcp.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,11 @@ struct ntttcp_test_endpoint{
6666
struct ntttcp_stream_client **client_streams; /* alloc memory for this if client/sender role */
6767
struct ntttcp_stream_server **server_streams; /* alloc memory for this if server/receiver role */
6868

69-
pthread_t *threads;
69+
pthread_t *threads; /* linux threads created to transfer test data */
7070
struct ntttcp_test_endpoint_results *results; /* test results */
7171

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

src/tcpstream.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ void *run_ntttcp_sender_tcp_stream( void *ptr )
6969
uint i = 0; //for loop iterator
7070
char *buffer; //send buffer
7171
int n = 0; //write n bytes to socket
72-
uint64_t nbytes = 0; //total bytes sent
7372
int ret = 0; //hold function return value
7473
uint total_sub_conn_created = 0; //track how many sub connections created in this thread
7574
struct ntttcp_stream_client *sc;
@@ -235,11 +234,10 @@ void *run_ntttcp_sender_tcp_stream( void *ptr )
235234
// PRINT_ERR("cannot write data to a socket");
236235
continue;
237236
}
238-
nbytes += n;
237+
sc->total_bytes_transferred += n;
239238
}
240239
}
241240
sc->num_conns_created = total_sub_conn_created;
242-
sc->total_bytes_transferred = nbytes;
243241
free(buffer);
244242

245243
CLEANUP:

src/throughputmanagement.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// ----------------------------------------------------------------------------------
2+
// Copyright (c) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
4+
// Author: Shihua (Simon) Xiao, [email protected]
5+
// ----------------------------------------------------------------------------------
6+
7+
#include "throughputmanagement.h"
8+
9+
void *run_ntttcp_throughput_management(void *ptr)
10+
{
11+
struct ntttcp_test_endpoint *tep = (struct ntttcp_test_endpoint *) ptr;
12+
uint n;
13+
uint64_t last_total_bytes, this_total_bytes, total_bytes;
14+
uint total_test_threads = 0;
15+
last_total_bytes = this_total_bytes = total_bytes = 0;
16+
17+
if (tep->test->client_role == true )
18+
total_test_threads = tep->test->server_ports * tep->test->threads_per_server_port;
19+
else
20+
total_test_threads = tep->test->server_ports;
21+
22+
wait_light_on();
23+
24+
while( is_light_turned_on(tep->test->duration == 0) ) {
25+
for (n = 0; n < total_test_threads; n++) {
26+
if (tep->test->client_role == true )
27+
this_total_bytes += tep->client_streams[n]->total_bytes_transferred;
28+
else
29+
this_total_bytes += tep->server_streams[n]->total_bytes_transferred;
30+
}
31+
32+
total_bytes = this_total_bytes - last_total_bytes;
33+
last_total_bytes = this_total_bytes;
34+
this_total_bytes = 0;
35+
36+
/* sleep 0.5 second, then calculate the throughput for this period */
37+
printf("%s: %s\r", "Real-time throughput", format_throughput(total_bytes, 0.5));
38+
fflush(stdout);
39+
usleep(500000);
40+
}
41+
42+
return NULL;
43+
}

src/throughputmanagement.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// ----------------------------------------------------------------------------------
2+
// Copyright (c) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
4+
// Author: Shihua (Simon) Xiao, [email protected]
5+
// ----------------------------------------------------------------------------------
6+
7+
#define _GNU_SOURCE
8+
#include "multithreading.h"
9+
#include "util.h"
10+
11+
void *run_ntttcp_throughput_management(void *ptr);

src/udpstream.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ void *run_ntttcp_sender_udp4_stream( struct ntttcp_stream_client * sc )
3232
char *buffer; //send buffer
3333

3434
int n = 0; //write n bytes to socket
35-
uint64_t nbytes = 0; //total bytes sent
3635
int ret = 0; //hold function return value
3736
uint i = 0; //for loop iterator
3837
uint total_sub_conn_created = 0; //track how many sub connections created in this thread
@@ -115,11 +114,10 @@ void *run_ntttcp_sender_udp4_stream( struct ntttcp_stream_client * sc )
115114
// printf("error: %d \n", errno);
116115
continue;
117116
}
118-
nbytes += n;
117+
sc->total_bytes_transferred += n;
119118
}
120119
}
121120
sc->num_conns_created = total_sub_conn_created;
122-
sc->total_bytes_transferred = nbytes;
123121
free(buffer);
124122

125123
CLEANUP:

0 commit comments

Comments
 (0)