With disks, O_DIRECT effectively bypasses all buffering/caching mechanisms and
ensures that the I/O is going directly to the disk. Since TCP is a streaming
protocol (like disk I/O), it also has a buffering mechanism. As with disks, it
is sometimes desirable to bypass buffering. To that end, we can use
TCP_NODELAY, which transmits the packet as soon as data is assembled,
regardless of whether it occupies a full frame.
Signed-off-by: Steven Noonan <snoonan@amazon.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
#include <errno.h>
#include <assert.h>
#include <netinet/in.h>
#include <errno.h>
#include <assert.h>
#include <netinet/in.h>
+#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/poll.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/poll.h>
unsigned int proto;
unsigned int listen;
unsigned int pingpong;
unsigned int proto;
unsigned int listen;
unsigned int pingpong;
};
struct udp_close_msg {
};
struct udp_close_msg {
+ {
+ .name = "nodelay",
+ .type = FIO_OPT_BOOL,
+ .off1 = offsetof(struct netio_options, nodelay),
+ .help = "Use TCP_NODELAY on TCP connections",
+ },
{
.name = "listen",
.type = FIO_OPT_STR_SET,
{
.name = "listen",
.type = FIO_OPT_STR_SET,
{
struct netio_data *nd = td->io_ops->data;
struct netio_options *o = td->eo;
{
struct netio_data *nd = td->io_ops->data;
struct netio_options *o = td->eo;
+ int type, domain, optval;
if (o->proto == FIO_TYPE_TCP) {
domain = AF_INET;
if (o->proto == FIO_TYPE_TCP) {
domain = AF_INET;
+ if (o->nodelay && o->proto == FIO_TYPE_TCP) {
+ optval = 1;
+ if (setsockopt(f->fd, IPPROTO_TCP, TCP_NODELAY, &optval, sizeof(int)) < 0) {
+ log_err("fio: cannot set TCP_NODELAY option on socket (%s), disable with 'nodelay=0'\n", strerror(errno));
+ return 1;
+ }
+ }
+
if (o->proto == FIO_TYPE_UDP)
return 0;
else if (o->proto == FIO_TYPE_TCP) {
if (o->proto == FIO_TYPE_UDP)
return 0;
else if (o->proto == FIO_TYPE_TCP) {
struct netio_data *nd = td->io_ops->data;
struct netio_options *o = td->eo;
socklen_t socklen = sizeof(nd->addr);
struct netio_data *nd = td->io_ops->data;
struct netio_options *o = td->eo;
socklen_t socklen = sizeof(nd->addr);
if (o->proto == FIO_TYPE_UDP) {
f->fd = nd->listenfd;
if (o->proto == FIO_TYPE_UDP) {
f->fd = nd->listenfd;
+ if (o->nodelay && o->proto == FIO_TYPE_TCP) {
+ optval = 1;
+ if (setsockopt(f->fd, IPPROTO_TCP, TCP_NODELAY, &optval, sizeof(int)) < 0) {
+ log_err("fio: cannot set TCP_NODELAY option on socket (%s), disable with 'nodelay=0'\n", strerror(errno));
+ return 1;
+ }
+ }
+
reset_all_stats(td);
td_set_runstate(td, state);
return 0;
reset_all_stats(td);
td_set_runstate(td, state);
return 0;