]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
OPTIM: h2: do not update committed streams if elasticity disabled
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 20 May 2026 07:01:04 +0000 (09:01 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 20 May 2026 07:52:50 +0000 (09:52 +0200)
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.

src/mux_h2.c

index 1c29cf5cc549aa10b3371376670bba63b7c970cc..37162fc3cbd7f4f08a9141988465861d577f7c64 100644 (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;