Date: Wed, 21 Apr 2010 00:52:56 +0000 (UTC) From: Robert Watson <rwatson@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r206972 - head/tools/tools/netrate/tcpp Message-ID: <201004210052.o3L0qu4m096704@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: rwatson Date: Wed Apr 21 00:52:55 2010 New Revision: 206972 URL: http://svn.freebsd.org/changeset/base/206972 Log: 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. Modified: head/tools/tools/netrate/tcpp/tcpp_client.c head/tools/tools/netrate/tcpp/tcpp_server.c Modified: head/tools/tools/netrate/tcpp/tcpp_client.c ============================================================================== --- head/tools/tools/netrate/tcpp/tcpp_client.c Wed Apr 21 00:26:41 2010 (r206971) +++ head/tools/tools/netrate/tcpp/tcpp_client.c Wed Apr 21 00:52:55 2010 (r206972) @@ -33,9 +33,11 @@ #include <sys/socket.h> #include <sys/sysctl.h> #include <sys/time.h> +#include <sys/uio.h> #include <sys/wait.h> #include <netinet/in.h> +#include <netinet/tcp.h> #include <err.h> #include <errno.h> @@ -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 *ke 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 *ke "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"); Modified: head/tools/tools/netrate/tcpp/tcpp_server.c ============================================================================== --- head/tools/tools/netrate/tcpp/tcpp_server.c Wed Apr 21 00:26:41 2010 (r206971) +++ head/tools/tools/netrate/tcpp/tcpp_server.c Wed Apr 21 00:52:55 2010 (r206972) @@ -37,6 +37,7 @@ #include <sys/wait.h> #include <netinet/in.h> +#include <netinet/tcp.h> #include <err.h> #include <fcntl.h> @@ -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");
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201004210052.o3L0qu4m096704>