[OPTIM] http: set MSG_MORE on response when a pipelined request is pending
Many times we see a lot of short responses in HTTP (typically 304 on a
reload). It is a waste of network bandwidth to send that many small packets
when we know we can merge them. When we know that another HTTP request is
following a response, we set BF_EXPECT_MORE on the response buffer, which
will turn MSG_MORE on exactly once. That way, multiple short responses can
leave pipelined if their corresponding requests were also pipelined.
diff --git a/src/stream_sock.c b/src/stream_sock.c
index 7e9dd2c..4a9434c 100644
--- a/src/stream_sock.c
+++ b/src/stream_sock.c
@@ -608,16 +608,20 @@
* tests.
*/
- if (MSG_NOSIGNAL) {
+ if (MSG_NOSIGNAL && MSG_MORE) {
unsigned int send_flag = MSG_DONTWAIT | MSG_NOSIGNAL;
- if (MSG_MORE &&
- ((b->to_forward && b->to_forward != BUF_INFINITE_FORWARD) ||
+ if (((b->to_forward && b->to_forward != BUF_INFINITE_FORWARD) ||
((b->flags & (BF_SHUTW|BF_SHUTW_NOW|BF_HIJACK)) == BF_SHUTW_NOW && (max == b->send_max)) ||
(max != b->l && max != b->send_max))
&& (fdtab[si->fd].flags & FD_FL_TCP)) {
send_flag |= MSG_MORE;
}
+ else if (b->flags & BF_EXPECT_MORE) {
+ /* it was forced on the buffer, this flag is one-shoot */
+ b->flags &= ~BF_EXPECT_MORE;
+ send_flag |= MSG_MORE;
+ }
ret = send(si->fd, b->w, max, send_flag);
} else {