]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] read optimizations based on the MSS
authorWilly Tarreau <w@1wt.eu>
Fri, 23 Mar 2007 22:02:09 +0000 (23:02 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 23 Mar 2007 22:02:09 +0000 (23:02 +0100)
Generally, if a recv() returns less bytes than the MSS, it means that
there is nothing left in the system's buffers, and that it's not worth
trying to read again because we are very likely to get nothing. A
default read low limit has been set to 1460 bytes below which we stop
reading.

This has brought a little speed boost on small objects while maintaining
the same speed on large objects.

include/common/defaults.h
src/stream_sock.c

index 89ee1041ce10f16b1d2cd16be1bd22b1a52d0119..e6552de8058145fb24ee3c5feddb42037fb4a63c 100644 (file)
 #define MAX_READ_POLL_LOOPS 4
 #endif
 
+// the number of bytes returned by a read below which we will not try to
+// poll the socket again. Generally, return values below the MSS are worthless
+// to try again.
+#ifndef MIN_RET_FOR_READ_LOOP
+#define MIN_RET_FOR_READ_LOOP 1460
+#endif
+
 // cookie delimitor in "prefix" mode. This character is inserted between the
 // persistence cookie and the original value. The '~' is allowed by RFC2965,
 // and should not be too common in server names.
index 4e081172500819f5f1388e14e5b562c0816bb064..f9e56272e4284e1b9c762cf2e30b4432b8376a72 100644 (file)
@@ -95,6 +95,15 @@ int stream_sock_read(int fd) {
                                }
 
                                b->total += ret;
+
+                               /* generally if we read something smaller than the 1 or 2 MSS,
+                                * it means that it's not worth trying to read again.
+                                */
+                               if (ret < MIN_RET_FOR_READ_LOOP)
+                                       break;
+                               if (!read_poll)
+                                       break;
+
                                /* we hope to read more data or to get a close on next round */
                                continue;
                        }