]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MEDIUM] re-implemented the multiple read polling
authorWilly Tarreau <w@1wt.eu>
Fri, 23 Mar 2007 21:39:59 +0000 (22:39 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 23 Mar 2007 21:39:59 +0000 (22:39 +0100)
Multiple read polling was temporarily disabled, which had the side
effect of burning huge amounts of CPU on large objects. It has now
been re-implemented with a limit of 8 calls per wake-up, which seems
to provide best results at least on Linux.

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

index 84032ae5627259706d64c26a861269ec271b67ba..89ee1041ce10f16b1d2cd16be1bd22b1a52d0119 100644 (file)
 #define MAX_HTTP_HDR    ((BUFSIZE+79)/80)
 #endif
 
+// max # of loops we can perform around a read() which succeeds.
+// It's very frequent that the system returns a few TCP segments at a time.
+#ifndef MAX_READ_POLL_LOOPS
+#define MAX_READ_POLL_LOOPS 4
+#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 91d5a5f8242b454b0b076f176f3d17b9c9a4a293..4e081172500819f5f1388e14e5b562c0816bb064 100644 (file)
 int stream_sock_read(int fd) {
        struct buffer *b = fdtab[fd].cb[DIR_RD].b;
        int ret, max;
+       int read_poll = MAX_READ_POLL_LOOPS;
 
 #ifdef DEBUG_FULL
        fprintf(stderr,"stream_sock_read : fd=%d, owner=%p\n", fd, fdtab[fd].owner);
 #endif
 
        if (fdtab[fd].state != FD_STERROR) {
-#ifdef FILL_BUFFERS
-               while (1)
-#else
-               do
-#endif
+               while (read_poll-- > 0)
                {
                        if (b->l == 0) { /* let's realign the buffer to optimize I/O */
                                b->r = b->w = b->lr  = b->data;
@@ -114,9 +111,6 @@ int stream_sock_read(int fd) {
                                break;
                        }
                } /* while(1) */
-#ifndef FILL_BUFFERS
-               while (0);
-#endif
        }
        else {
                b->flags |= BF_READ_ERROR;