Skip to content

Commit

Permalink
OPTIM: mux-h2/zero-copy: don't allocate more buffers per connections …
Browse files Browse the repository at this point in the history
…than streams

It's the exact same as commit 0a7ab70 ("OPTIM: mux-h2: don't allocate
more buffers per connections than streams"), but for the zero-copy case
this time. Previously it was only done on the regular snd_buf() path, but
this one is needed as well. A transfer on 16 parallel streams now consumes
half of the memory, and a single stream consumes much less.

An alternate approach would be worth investigating in the future, based
on the same principle as the CF_STREAMER_FAST at the higher level: in
short, by monitoring how many mux buffers we write at once before refilling
them, we would get an idea of how much is worth keeping in buffers max,
given that anything beyond would just waste memory. Some tests show that
a single buffer already seems almost as good, except for single-stream
transfers, which is why it's worth spending more time on this.
  • Loading branch information
wtarreau committed Nov 28, 2023
1 parent e97489a commit d656ac7
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/mux_h2.c
Original file line number Diff line number Diff line change
Expand Up @@ -6967,6 +6967,16 @@ static size_t h2_nego_ff(struct stconn *sc, struct buffer *input, size_t count,

mbuf = br_tail(h2c->mbuf);
retry:
if (br_count(h2c->mbuf) > h2c->nb_streams) {
/* more buffers than streams allocated, pointless
* to continue, we'd use more RAM for no reason.
*/
h2s->flags |= H2_SF_BLK_MROOM;
h2s->sd->iobuf.flags |= IOBUF_FL_FF_BLOCKED;
TRACE_STATE("waiting for room in output buffer", H2_EV_TX_FRAME|H2_EV_TX_DATA|H2_EV_H2S_BLK, h2c->conn, h2s);
goto end;
}

if (!h2_get_buf(h2c, mbuf)) {
h2c->flags |= H2_CF_MUX_MALLOC;
h2s->flags |= H2_SF_BLK_MROOM;
Expand Down

0 comments on commit d656ac7

Please sign in to comment.