From 0e4ae43e17351d26d597e0ef1e25310d2ee0b195 Mon Sep 17 00:00:00 2001 From: Robert Watson Date: Wed, 21 Apr 2010 00:52:55 +0000 Subject: [PATCH] Merge @176820, @176822, @177156 to tcpp from P4 to HEAD: Improve accuracy of connection data transfer math. Disable Nagle's algorithm to avoid delaying transfers of data -- will want to refine this to combine payload with header transfer, however. Now that we're running w/o Nagle, try to send the initial data burst with the header in a single TCP segment. Prefer %zu to %ju for size_t. MFC after: 1 week Sponsored by: Juniper, Inc. --- tools/tools/netrate/tcpp/tcpp_client.c | 47 +++++++++++++++++++------- tools/tools/netrate/tcpp/tcpp_server.c | 5 +++ 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/tools/tools/netrate/tcpp/tcpp_client.c b/tools/tools/netrate/tcpp/tcpp_client.c index 15df06eda773..6c3e800366b9 100644 --- a/tools/tools/netrate/tcpp/tcpp_client.c +++ b/tools/tools/netrate/tcpp/tcpp_client.c @@ -33,9 +33,11 @@ #include #include #include +#include #include #include +#include #include #include @@ -82,6 +84,7 @@ static int kq; static int started; /* Number started so far. */ static int finished; /* Number finished so far. */ static int counter; /* IP number offset. */ +static uint64_t payload_len; static struct connection * tcpp_client_newconn(void) @@ -109,6 +112,9 @@ tcpp_client_newconn(void) i = 1; if (setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, &i, sizeof(i)) < 0) err(-1, "setsockopt"); + i = 1; + if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &i, sizeof(i)) < 0) + err(-1, "setsockopt"); #if 0 i = 1; if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(i)) < 0) @@ -131,7 +137,7 @@ tcpp_client_newconn(void) conn->conn_magic = CONNECTION_MAGIC; conn->conn_fd = fd; conn->conn_header.th_magic = TCPP_MAGIC; - conn->conn_header.th_len = bflag; + conn->conn_header.th_len = payload_len; tcpp_header_encode(&conn->conn_header); EV_SET(&kev, fd, EVFILT_WRITE, EV_ADD, 0, 0, conn); @@ -156,16 +162,22 @@ static void tcpp_client_handleconn(struct kevent *kev) { struct connection *conn; - ssize_t len; + struct iovec iov[2]; + ssize_t len, header_left; conn = kev->udata; if (conn->conn_magic != CONNECTION_MAGIC) errx(-1, "tcpp_client_handleconn: magic"); if (conn->conn_header_sent < sizeof(conn->conn_header)) { - len = write(conn->conn_fd, ((u_char *)&conn->conn_header) + - conn->conn_header_sent, sizeof(conn->conn_header) - - conn->conn_header_sent); + header_left = sizeof(conn->conn_header) - + conn->conn_header_sent; + iov[0].iov_base = ((u_char *)&conn->conn_header) + + conn->conn_header_sent; + iov[0].iov_len = header_left; + iov[1].iov_base = buffer; + iov[1].iov_len = min(sizeof(buffer), payload_len); + len = writev(conn->conn_fd, iov, 2); if (len < 0) { tcpp_client_closeconn(conn); err(-1, "tcpp_client_handleconn: header write"); @@ -175,10 +187,14 @@ tcpp_client_handleconn(struct kevent *kev) errx(-1, "tcpp_client_handleconn: header write " "premature EOF"); } - conn->conn_header_sent += len; + if (len > header_left) { + conn->conn_data_sent += (len - header_left); + conn->conn_header_sent += header_left; + } else + conn->conn_header_sent += len; } else { len = write(conn->conn_fd, buffer, min(sizeof(buffer), - bflag - conn->conn_data_sent)); + payload_len - conn->conn_data_sent)); if (len < 0) { tcpp_client_closeconn(conn); err(-1, "tcpp_client_handleconn: data write"); @@ -189,12 +205,12 @@ tcpp_client_handleconn(struct kevent *kev) "premature EOF"); } conn->conn_data_sent += len; - if (conn->conn_data_sent >= bflag) { - /* - * All is well. - */ - tcpp_client_closeconn(conn); - } + } + if (conn->conn_data_sent >= payload_len) { + /* + * All is well. + */ + tcpp_client_closeconn(conn); } } @@ -261,6 +277,11 @@ tcpp_client(void) pid_t pid; int i, failed, status; + if (bflag < sizeof(struct tcpp_header)) + errx(-1, "Can't use -b less than %zu\n", + sizeof(struct tcpp_header)); + payload_len = bflag - sizeof(struct tcpp_header); + pid_list = malloc(sizeof(*pid_list) * pflag); if (pid_list == NULL) err(-1, "malloc pid_list"); diff --git a/tools/tools/netrate/tcpp/tcpp_server.c b/tools/tools/netrate/tcpp/tcpp_server.c index 8101005b2bd5..76f5e8d51527 100644 --- a/tools/tools/netrate/tcpp/tcpp_server.c +++ b/tools/tools/netrate/tcpp/tcpp_server.c @@ -37,6 +37,7 @@ #include #include +#include #include #include @@ -239,6 +240,10 @@ tcpp_server_worker(int workernum) if (setsockopt(listen_sock, SOL_SOCKET, SO_REUSEPORT, &i, sizeof(i)) < 0) err(-1, "setsockopt"); + i = 1; + if (setsockopt(listen_sock, IPPROTO_TCP, TCP_NODELAY, &i, sizeof(i)) + < 0) + err(-1, "setsockopt"); if (bind(listen_sock, (struct sockaddr *)&localipbase, sizeof(localipbase)) < 0) err(-1, "bind");