From: Willy Tarreau Date: Thu, 18 Jul 2013 20:21:54 +0000 (+0200) Subject: OPTIM: splicing: use splice() for the last block when relevant X-Git-Tag: v1.5-dev20~330 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fa8e2bc68c583a227ebc78bab5779b84065b28da;p=thirdparty%2Fhaproxy.git OPTIM: splicing: use splice() for the last block when relevant Splicing is avoided for small transfers because it's generally cheaper to perform a couple of recv+send calls than pipe+splice+splice. This has the consequence that the last chunk of a large transfer may be transferred using recv+send if it's less than 4 kB. But when the pipe is already set up, it's better to use splice() to read the pending data, since they will get merged with the pending ones. This is what now happens everytime the reader is slower than the writer. Note that this change alone could have fixed most of the CPU hog bug, except at the end when only the close was pending. --- diff --git a/src/stream_interface.c b/src/stream_interface.c index 905612cef5..33f1d0efc0 100644 --- a/src/stream_interface.c +++ b/src/stream_interface.c @@ -934,7 +934,8 @@ static void si_conn_recv_cb(struct connection *conn) * using a buffer. */ if (conn->xprt->rcv_pipe && - chn->to_forward >= MIN_SPLICE_FORWARD && chn->flags & CF_KERN_SPLICING) { + (chn->pipe || chn->to_forward >= MIN_SPLICE_FORWARD) && + chn->flags & CF_KERN_SPLICING) { if (buffer_not_empty(chn->buf)) { /* We're embarrassed, there are already data pending in * the buffer and we don't want to have them at two