Skip to content

Commit 0735a76

Browse files
Merge pull request #86 from kylestanfield/tcpSmallPackets
Add no_delay and no_cork flags to help tcp_stream send small packets
2 parents 80df2c6 + 6cb4af0 commit 0735a76

File tree

6 files changed

+16
-0
lines changed

6 files changed

+16
-0
lines changed

common.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,13 @@ void set_tcp_tx_delay(int fd, int delay, struct callbacks *cb)
233233
PLOG_ERROR(cb, "setsockopt(TCP_TX_DELAY)");
234234
}
235235

236+
void set_tcp_no_delay(int fd, struct callbacks *cb)
237+
{
238+
int value = true;
239+
if (setsockopt(fd, SOL_TCP, TCP_NODELAY, &value, sizeof(value)))
240+
PLOG_ERROR(cb, "setsockopt(TCP_NODELAY)");
241+
}
242+
236243
void fill_random(char *buf, int size)
237244
{
238245
int fd, chunk, done = 0;

common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ void set_freebind(int fd, struct callbacks *cb);
157157
void set_debug(int fd, int onoff, struct callbacks *cb);
158158
void set_mark(int fd, int mark, struct callbacks *cb);
159159
void set_tcp_tx_delay(int fd, int delay, struct callbacks *cb);
160+
void set_tcp_no_delay(int fd, struct callbacks *cb);
160161
void fill_random(char *buf, int size);
161162
int do_close(int fd);
162163
struct addrinfo *copy_addrinfo(const struct addrinfo *);

define_all_flags.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ struct flags_parser *add_flags_tcp(struct flags_parser *fp)
7272
DEFINE_FLAG(fp, bool, pin_numa, false, 'N', "Pin threads to CPU cores");
7373
#endif
7474
DEFINE_FLAG(fp, int, tcp_tx_delay, 0, 't', "Force usec delay in TCP flows");
75+
DEFINE_FLAG(fp, bool, no_delay, false, 0, "Set TCP_NODELAY sockopt on data sockets to disable Nagle's algorithm");
7576

7677
/* Return the updated fp */
7778
return (fp);
@@ -149,6 +150,7 @@ struct flags_parser *add_flags_tcp_stream(struct flags_parser *fp)
149150
DEFINE_FLAG(fp, bool, split_bidir , false, 0, "Bidirectional using separate tx/rx sockets");
150151
DEFINE_FLAG(fp, bool, enable_tcp_maerts, false, 'M', "Enables TCP_MAERTS test (server writes and client reads). It overrides enable_read, and enable_write");
151152
DEFINE_FLAG(fp, bool, async_connect, false, 0, "use non blocking connect");
153+
DEFINE_FLAG(fp, bool, no_cork, false, 0, "Do not set MSG_MORE when sending over data sockets.");
152154

153155
/* Return the updated fp */
154156
return (fp);

lib.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ struct options {
9494
bool skip_rx_copy;
9595
bool tx_zerocopy;
9696
bool rx_zerocopy;
97+
bool no_delay;
98+
bool no_cork;
9799
bool time_wait;
98100
double interval;
99101
long long max_pacing_rate;

socket.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ static void socket_init_not_established(struct thread *t, int s)
6161
if (err)
6262
PLOG_ERROR(t->cb, "setsockopt(SO_LINGER)");
6363
}
64+
if (opts->no_delay)
65+
set_tcp_no_delay(s, cb);
6466
}
6567

6668
/*

tcp_stream_main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ int main(int argc, char **argv)
6060
opts.recv_flags = MSG_TRUNC;
6161
if (opts.tx_zerocopy)
6262
opts.send_flags = MSG_ZEROCOPY;
63+
if (!opts.no_cork)
64+
opts.send_flags |= MSG_MORE;
6365

6466
flags_parser_dump(fp);
6567
flags_parser_destroy(fp);

0 commit comments

Comments
 (0)