[PATCH] Using TCP_NODELAY unconditionally

Tobias Ringstrom tori at ringstrom.mine.nu
Sat Jan 19 21:42:45 EST 2002


Dear OpenSSH maintainers,

When analyzing the performance of sftp some weeks ago, I discovered that
the cause of the horrible performance was the use of the Nagle algorithm
on the ssh TCP connection, i.e. TCP_NODELAY was not used.

I propose that the following patch is applied, enabling TCP_NODELAY for
both ssh and sshd, unconditionally.  Since the SSH channel is packet
bases, if we want to reduce the amount of data on the wire, we should use
a Nagle-type algorithm before making packets of the data.  It is more
efficient to make one SSH packet of two small data "chunks" than to make
two packets of the data chunks, even if both fit within one TCP packet.

I also have a patch which implements overlapping read and write requests
for the sftp client.  The patch was posted to the list at the time, but I 
see no reason to apply that patch until the TCP_NODELAY issue has been 
resolved.

/Tobias


diff -ru openssh-3.0.2p1.orig/packet.c openssh-3.0.2p1.nodelay/packet.c
--- openssh-3.0.2p1.orig/packet.c	Mon Nov 12 01:07:58 2001
+++ openssh-3.0.2p1.nodelay/packet.c	Thu Jan 17 20:40:47 2002
@@ -1180,7 +1180,6 @@
 	int lowdelay = IPTOS_LOWDELAY;
 	int throughput = IPTOS_THROUGHPUT;
 #endif
-	int on = 1;
 
 	if (called)
 		return;
@@ -1198,7 +1197,7 @@
 	if (interactive) {
 		/*
 		 * Set IP options for an interactive connection.  Use
-		 * IPTOS_LOWDELAY and TCP_NODELAY.
+		 * IPTOS_LOWDELAY.
 		 */
 #if defined(IP_TOS) && !defined(IP_TOS_IS_BROKEN)
 		if (packet_connection_is_ipv4()) {
@@ -1208,9 +1207,6 @@
 				    strerror(errno));
 		}
 #endif
-		if (setsockopt(connection_in, IPPROTO_TCP, TCP_NODELAY, (void *) &on,
-		    sizeof(on)) < 0)
-			error("setsockopt TCP_NODELAY: %.100s", strerror(errno));
 	} else if (packet_connection_is_ipv4()) {
 		/*
 		 * Set IP options for a non-interactive connection.  Use
diff -ru openssh-3.0.2p1.orig/sshconnect.c openssh-3.0.2p1.nodelay/sshconnect.c
--- openssh-3.0.2p1.orig/sshconnect.c	Wed Oct 10 07:07:45 2001
+++ openssh-3.0.2p1.nodelay/sshconnect.c	Thu Jan 17 20:09:11 2002
@@ -370,6 +370,7 @@
 	linger.l_onoff = 1;
 	linger.l_linger = 5;
 	setsockopt(sock, SOL_SOCKET, SO_LINGER, (void *)&linger, sizeof(linger));
+	setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (void *) &on, sizeof(on));
 
 	/* Set keepalives if requested. */
 	if (options.keepalives &&
diff -ru openssh-3.0.2p1.orig/sshd.c openssh-3.0.2p1.nodelay/sshd.c
--- openssh-3.0.2p1.orig/sshd.c	Mon Nov 12 01:07:12 2001
+++ openssh-3.0.2p1.nodelay/sshd.c	Thu Jan 17 20:42:24 2002
@@ -1118,6 +1118,7 @@
 	linger.l_onoff = 1;
 	linger.l_linger = 5;
 	setsockopt(sock_in, SOL_SOCKET, SO_LINGER, (void *) &linger, sizeof(linger));
+	setsockopt(sock_in, IPPROTO_TCP, TCP_NODELAY, (void *) &on, sizeof(on));
 
 	/* Set keepalives if requested. */
 	if (options.keepalives &&







More information about the openssh-unix-dev mailing list