MINOR: mux-h2: copy small data blocks more often and reduce the number of pauses

We tend to refrain from sending data a bit too much in the H2 mux :
whenever there are pending data in the buffer and we try to copy
something larger than 1/4 of the buffer we prefer to pause. This
is suboptimal for medium-sized objects which have to send their
headers and later their data.

This patch slightly changes this by allowing a copy of a large block
if it fits at once and if the realign cost is small, i.e. the pending
data are small or the block fits in the contiguous area. Depending on
the object size this measurably improves the download performance by
between 1 and 10%, and possibly lowers the transfer latency for medium
objects.
This commit is contained in:
Willy Tarreau 2019-03-21 17:47:28 +01:00
parent fd8bd4521a
commit 8ab128c06a

View File

@ -4733,13 +4733,17 @@ static size_t h2s_htx_frt_make_resp_data(struct h2s *h2s, struct buffer *buf, si
void *old_area = h2c->mbuf.area; void *old_area = h2c->mbuf.area;
if (b_data(&h2c->mbuf)) { if (b_data(&h2c->mbuf)) {
/* too bad there are data left there. If we have less /* Too bad there are data left there. We're willing to memcpy/memmove
* than 1/4 of the mbuf's size and everything fits, * up to 1/4 of the buffer, which means that it's OK to copy a large
* we'll perform a copy anyway. Otherwise we'll pretend * frame into a buffer containing few data if it needs to be realigned,
* the mbuf is full and wait. * and that it's also OK to copy few data without realigning. Otherwise
* we'll pretend the mbuf is full and wait for it to become empty.
*/ */
if (fsize <= b_size(&h2c->mbuf) / 4 && fsize + 9 <= b_room(&h2c->mbuf)) if (fsize + 9 <= b_room(&h2c->mbuf) &&
(b_data(&h2c->mbuf) <= b_size(&h2c->mbuf) / 4 ||
(fsize <= b_size(&h2c->mbuf) / 4 && fsize + 9 <= b_contig_space(&h2c->mbuf))))
goto copy; goto copy;
h2c->flags |= H2_CF_MUX_MFULL; h2c->flags |= H2_CF_MUX_MFULL;
h2s->flags |= H2_SF_BLK_MROOM; h2s->flags |= H2_SF_BLK_MROOM;
goto end; goto end;