]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[OPTIM] stream_sock: avoid fast-forwarding of partial data
authorWilly Tarreau <w@1wt.eu>
Wed, 11 May 2011 18:32:36 +0000 (20:32 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 30 May 2011 16:42:41 +0000 (18:42 +0200)
Fast-forwarding between file descriptors is nice but can be counter-productive
when only one part of the buffer is forwarded, because it can result in doubling
the number of send() syscalls. This is what happens on HTTP chunking, because
the chunk data are sent, then the CRLF + next chunk size are parsed and immediately
scheduled for forwarding. This results in two send() for the same block while a
single one would have done it.

src/stream_sock.c

index b08134aef724a393b29e1349865e8eabfaf9fff1..5539cd205b367f6c7c508307195554d8b44647de 100644 (file)
@@ -473,8 +473,14 @@ int stream_sock_read(int fd) {
        } /* while (1) */
 
  out_wakeup:
-       /* We might have some data the consumer is waiting for */
-       if (!(b->flags & BF_OUT_EMPTY) && (b->cons->flags & SI_FL_WAIT_DATA)) {
+       /* We might have some data the consumer is waiting for.
+        * We can do fast-forwarding, but we avoid doing this for partial
+        * buffers, because it is very likely that it will be done again
+        * immediately afterwards once the following data is parsed (eg:
+        * HTTP chunking).
+        */
+       if ((b->pipe || b->send_max == b->l)
+           && (b->cons->flags & SI_FL_WAIT_DATA)) {
                int last_len = b->pipe ? b->pipe->data : 0;
 
                b->cons->chk_snd(b->cons);