Since we disabled Nagle's algorithm we may send very small packets
over the wire in some situations where we are calling send(2) from
states that are responsible for small parts of the protocol. By
setting the MSG_MORE flag we can indicate to the kernel that more data
will follow (usually) immediately and so it can append the data to the
same outgoing packet.
Although there is some variability in the test there is a measurable
benefit. Using this test:
$ time nbdkit memory 100M --run 'examples/threaded-reads-and-writes localhost
10809'
before applying this patch:
real 0m54.151s
real 0m54.950s
real 0m55.927s
and after applying this patch:
real 0m39.154s
real 0m44.249s
real 0m44.027s
Thanks: Eric Blake for suggesting this change.
---
generator/states-issue-command.c | 2 ++
generator/states-newstyle-opt-export-name.c | 1 +
generator/states-newstyle-opt-go.c | 3 +++
generator/states-newstyle-opt-set-meta-context.c | 5 +++++
4 files changed, 11 insertions(+)
diff --git a/generator/states-issue-command.c b/generator/states-issue-command.c
index 627a54f..cce43d7 100644
--- a/generator/states-issue-command.c
+++ b/generator/states-issue-command.c
@@ -42,6 +42,8 @@
h->request.count = htobe32 ((uint32_t) cmd->count);
h->wbuf = &h->request;
h->wlen = sizeof (h->request);
+ if (cmd->type == NBD_CMD_WRITE)
+ h->wflags = MSG_MORE;
SET_NEXT_STATE (%SEND_REQUEST);
return 0;
diff --git a/generator/states-newstyle-opt-export-name.c
b/generator/states-newstyle-opt-export-name.c
index 774c93c..968cea8 100644
--- a/generator/states-newstyle-opt-export-name.c
+++ b/generator/states-newstyle-opt-export-name.c
@@ -25,6 +25,7 @@
h->sbuf.option.optlen = strlen (h->export_name);
h->wbuf = &h->sbuf;
h->wlen = sizeof h->sbuf.option;
+ h->wflags = MSG_MORE;
SET_NEXT_STATE (%SEND);
return 0;
diff --git a/generator/states-newstyle-opt-go.c b/generator/states-newstyle-opt-go.c
index eea70cb..06bbaca 100644
--- a/generator/states-newstyle-opt-go.c
+++ b/generator/states-newstyle-opt-go.c
@@ -26,6 +26,7 @@
htobe32 (/* exportnamelen */ 4 + strlen (h->export_name) + /* nrinfos */ 2);
h->wbuf = &h->sbuf;
h->wlen = sizeof h->sbuf.option;
+ h->wflags = MSG_MORE;
SET_NEXT_STATE (%SEND);
return 0;
@@ -38,6 +39,7 @@
h->sbuf.len = htobe32 (exportnamelen);
h->wbuf = &h->sbuf;
h->wlen = 4;
+ h->wflags = MSG_MORE;
SET_NEXT_STATE (%SEND_EXPORTNAMELEN);
}
return 0;
@@ -48,6 +50,7 @@
case 0:
h->wbuf = h->export_name;
h->wlen = strlen (h->export_name);
+ h->wflags = MSG_MORE;
SET_NEXT_STATE (%SEND_EXPORT);
}
return 0;
diff --git a/generator/states-newstyle-opt-set-meta-context.c
b/generator/states-newstyle-opt-set-meta-context.c
index 1cd65c3..7148774 100644
--- a/generator/states-newstyle-opt-set-meta-context.c
+++ b/generator/states-newstyle-opt-set-meta-context.c
@@ -47,6 +47,7 @@
h->sbuf.option.optlen = htobe32 (len);
h->wbuf = &h->sbuf;
h->wlen = sizeof (h->sbuf.option);
+ h->wflags = MSG_MORE;
SET_NEXT_STATE (%SEND);
return 0;
@@ -57,6 +58,7 @@
h->sbuf.len = htobe32 (strlen (h->export_name));
h->wbuf = &h->sbuf.len;
h->wlen = sizeof h->sbuf.len;
+ h->wflags = MSG_MORE;
SET_NEXT_STATE (%SEND_EXPORTNAMELEN);
}
return 0;
@@ -67,6 +69,7 @@
case 0:
h->wbuf = h->export_name;
h->wlen = strlen (h->export_name);
+ h->wflags = MSG_MORE;
SET_NEXT_STATE (%SEND_EXPORTNAME);
}
return 0;
@@ -79,6 +82,7 @@
htobe32 (nbd_internal_string_list_length (h->request_meta_contexts));
h->wbuf = &h->sbuf;
h->wlen = sizeof h->sbuf.nrqueries;
+ h->wflags = MSG_MORE;
SET_NEXT_STATE (%SEND_NRQUERIES);
}
return 0;
@@ -103,6 +107,7 @@
h->sbuf.len = htobe32 (strlen (query));
h->wbuf = &h->sbuf.len;
h->wlen = sizeof h->sbuf.len;
+ h->wflags = MSG_MORE;
SET_NEXT_STATE (%SEND_QUERYLEN);
return 0;
--
2.21.0