OPTIM: h2: do not update committed streams if elasticity disabled

When streams-elasticity is enabled in the configuration, H2 mux is
responsible to update the global committed_extra_streams value.

Adjust these operations to ensure they are skipped if streams-elasticity
is disabled, which is the current default. This prevents unnecessary
atomic operations in this case.

No need to backport unless streams-elasticity feature is picked in older
releases.
This commit is contained in:
Amaury Denoyelle 2026-05-20 09:01:04 +02:00
parent ad3562fea1
commit 33c8270903

View file

@ -1456,7 +1456,7 @@ static int h2_init(struct connection *conn, struct proxy *prx, struct session *s
if (max_strm && h2c->streams_hard_limit > max_strm)
h2c->streams_limit = h2c->streams_hard_limit = max_strm;
if (h2c->streams_hard_limit > 1)
if (global.tune.streams_elasticity && h2c->streams_hard_limit > 1)
_HA_ATOMIC_ADD(&tg_ctx->committed_extra_streams, h2c->streams_hard_limit - 1);
}
@ -1530,7 +1530,7 @@ static int h2_init(struct connection *conn, struct proxy *prx, struct session *s
/* Unnecessary code for now as fail_stream only occurs with BE conns.
* Still better though to keep it to prevent future mistakes.
*/
if (!(h2c->flags & H2_CF_IS_BACK) && h2c->streams_hard_limit > 1)
if (!(h2c->flags & H2_CF_IS_BACK) && global.tune.streams_elasticity && h2c->streams_hard_limit > 1)
_HA_ATOMIC_SUB(&tg_ctx->committed_extra_streams, h2c->streams_hard_limit - 1);
hpack_dht_free(h2c->ddht);
fail:
@ -1610,7 +1610,7 @@ static void h2_release(struct h2c *h2c)
if (!conn || !conn_is_reverse(conn))
HA_ATOMIC_DEC(&h2c->px_counters->open_conns);
if (!(h2c->flags & H2_CF_IS_BACK) && h2c->streams_hard_limit > 1)
if (!(h2c->flags & H2_CF_IS_BACK) && global.tune.streams_elasticity && h2c->streams_hard_limit > 1)
_HA_ATOMIC_SUB(&tg_ctx->committed_extra_streams, h2c->streams_hard_limit - 1);
pool_free(pool_head_h2_rx_bufs, h2c->shared_rx_bufs);
@ -4200,7 +4200,7 @@ static int h2_conn_reverse(struct h2c *h2c)
/* the connection was accounted as frontend streams before
* reversal, we must undo that accounting now.
*/
if (h2c->streams_hard_limit > 1)
if (h2c->streams_hard_limit > 1 && global.tune.streams_elasticity)
_HA_ATOMIC_SUB(&tg_ctx->committed_extra_streams, h2c->streams_hard_limit - 1);
h2c->flags |= H2_CF_IS_BACK;
@ -4222,7 +4222,7 @@ static int h2_conn_reverse(struct h2c *h2c)
struct proxy *prx = l->bind_conf->frontend;
/* backend connections becoming frontend need accounting. */
if (h2c->streams_hard_limit > 1)
if (h2c->streams_hard_limit > 1 && global.tune.streams_elasticity)
_HA_ATOMIC_ADD(&tg_ctx->committed_extra_streams, h2c->streams_hard_limit - 1);
h2c->flags &= ~H2_CF_IS_BACK;