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.
#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.
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;
break;
}
} /* while(1) */
-#ifndef FILL_BUFFERS
- while (0);
-#endif
}
else {
b->flags |= BF_READ_ERROR;