From b8949f1ed0cc13dd9fd75a7b08bbc976b2f508cc Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 23 Mar 2007 22:39:59 +0100 Subject: [PATCH] [MEDIUM] re-implemented the multiple read polling 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 | 6 ++++++ src/stream_sock.c | 10 ++-------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/common/defaults.h b/include/common/defaults.h index 84032ae56..89ee1041c 100644 --- a/include/common/defaults.h +++ b/include/common/defaults.h @@ -58,6 +58,12 @@ #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. diff --git a/src/stream_sock.c b/src/stream_sock.c index 91d5a5f82..4e0811725 100644 --- a/src/stream_sock.c +++ b/src/stream_sock.c @@ -40,17 +40,14 @@ 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;