[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.
diff --git a/include/common/defaults.h b/include/common/defaults.h
index 84032ae..89ee104 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 91d5a5f..4e08117 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 @@
break;
}
} /* while(1) */
-#ifndef FILL_BUFFERS
- while (0);
-#endif
}
else {
b->flags |= BF_READ_ERROR;