Skip to contentSkip to conversation

nbd/server: Request TCP_NODELAY

PATCH Superseded Eric Blake 2 participants 3 messages Mar 27, 2023 – Mar 28, 2023

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Eric Blake

author
#0 lore raw

PATCH 1/1 nbd/server: Request TCP_NODELAY

Nagle's algorithm adds latency in order to reduce network packet overhead on small packets. But when we are already using corking to merge smaller packets into transactional requests, the extra delay from TCP defaults just gets in the way.

For reference, qemu as an NBD client already requests TCP_NODELAY (see nbd_connect() in nbd/client-connection.c); as does libnbd as a client [1], and nbdkit as a server [2].

[1] https://gitlab.com/nbdkit/libnbd/-/blob/a48a1142/generator/states-connect.c#L39
[2] https://gitlab.com/nbdkit/nbdkit/-/blob/45b72f5b/server/sockets.c#L430

CC Florian Westphal <[email protected]>
---
 nbd/server.c | 1 +
 1 file changed, 1 insertion(+)
nbd/server.c +1 -0
index a4750e41880..976223860bf 100644
@@ -2755,6 +2755,7 @@ void nbd_client_new(QIOChannelSocket *sioc,
     }
     client->tlsauthz = g_strdup(tlsauthz);
     client->sioc = sioc;
+    qio_channel_set_delay(QIO_CHANNEL(cioc), false);
     object_ref(OBJECT(client->sioc));
     client->ioc = QIO_CHANNEL(sioc);
     object_ref(OBJECT(client->ioc));

base-commit: e3debd5e7d0ce031356024878a0a18b9d109354a

Signature · 1 line
2.39.2
#1 lore raw
Quoted 23 lines · Eric Blake

Nagle's algorithm adds latency in order to reduce network packet overhead on small packets. But when we are already using corking to merge smaller packets into transactional requests, the extra delay from TCP defaults just gets in the way.

For reference, qemu as an NBD client already requests TCP_NODELAY (see nbd_connect() in nbd/client-connection.c); as does libnbd as a client [1], and nbdkit as a server [2].

[1] https://gitlab.com/nbdkit/libnbd/-/blob/a48a1142/generator/states-connect.c#L39
[2] https://gitlab.com/nbdkit/nbdkit/-/blob/45b72f5b/server/sockets.c#L430

CC Florian Westphal <[email protected]>
---
 nbd/server.c | 1 +
 1 file changed, 1 insertion(+)
nbd/server.c +0 -0
index a4750e41880..976223860bf 100644

nbd/server.c void nbd_client_new(QIOChannelSocket *sioc, · line 2758

Quoted 4 lines
nbd/server.c +1 -0
@@ -2755,6 +2755,7 @@ void nbd_client_new(QIOChannelSocket *sioc,
     }
     client->tlsauthz = g_strdup(tlsauthz);
     client->sioc = sioc;
+    qio_channel_set_delay(QIO_CHANNEL(cioc), false);

../nbd/server.c: In function 'nbd_client_new':
../nbd/server.c:2763:39: error: 'cioc' undeclared (first use in this function); did you mean 'sioc'?

Other than that this looks good to me.

author
#2 lore raw
Quoted 32 lines · Florian Westphal
Quoted 23 lines · Eric Blake

Nagle's algorithm adds latency in order to reduce network packet overhead on small packets. But when we are already using corking to merge smaller packets into transactional requests, the extra delay from TCP defaults just gets in the way.

For reference, qemu as an NBD client already requests TCP_NODELAY (see nbd_connect() in nbd/client-connection.c); as does libnbd as a client [1], and nbdkit as a server [2].

[1] https://gitlab.com/nbdkit/libnbd/-/blob/a48a1142/generator/states-connect.c#L39
[2] https://gitlab.com/nbdkit/nbdkit/-/blob/45b72f5b/server/sockets.c#L430

CC Florian Westphal <[email protected]>
---
 nbd/server.c | 1 +
 1 file changed, 1 insertion(+)
nbd/server.c +0 -0
index a4750e41880..976223860bf 100644

nbd/server.c void nbd_client_new(QIOChannelSocket *sioc, · line 2758

Quoted 4 lines
nbd/server.c +1 -0
@@ -2755,6 +2755,7 @@ void nbd_client_new(QIOChannelSocket *sioc,
     }
     client->tlsauthz = g_strdup(tlsauthz);
     client->sioc = sioc;
+    qio_channel_set_delay(QIO_CHANNEL(cioc), false);

../nbd/server.c: In function 'nbd_client_new':
../nbd/server.c:2763:39: error: 'cioc' undeclared (first use in this function); did you mean 'sioc'?

Quoted 1 line

Other than that this looks good to me.

Arrgh. Bitten by hitting send before saving the edits in my buffer. Yes, the obvious fix is needed and intended.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org