]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
OPTIM: server: start to use aligned allocs in server quic-interop
authorWilly Tarreau <w@1wt.eu>
Mon, 11 Aug 2025 15:43:51 +0000 (17:43 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 11 Aug 2025 17:55:30 +0000 (19:55 +0200)
This is currently for per-thread arrays like idle conns etc. We're
now cache-aligning the per-thread arrays so as to put an end to false
sharing. A comparative test between no alignment and alignment on a
simple config with round robin between 4 servers showed an average
rate of 1.75M/s vs 1.72M/s before for 100M requests. The gain seems
to be more commonly less than 1% however. This should mostly help
make measurements more reproducible across multiple runs.

src/server.c

index e53d4847cba790b56854ecbf9ac87bd33d2d6f7c..c299d202bf410caf18947ef271fa87c1c18edfd5 100644 (file)
@@ -3122,9 +3122,9 @@ void srv_free_params(struct server *srv)
        free(srv->hostname);
        free(srv->hostname_dn);
        free((char*)srv->conf.file);
-       free(srv->per_thr);
-       free(srv->per_tgrp);
-       free(srv->curr_idle_thr);
+       ha_aligned_free(srv->per_thr);
+       ha_aligned_free(srv->per_tgrp);
+       ha_aligned_free(srv->curr_idle_thr);
        free(srv->pool_conn_name);
        release_sample_expr(srv->pool_conn_name_expr);
        free(srv->resolvers_id);
@@ -3482,7 +3482,7 @@ int srv_init(struct server *srv)
 
        /* initialize idle conns lists */
        if (srv->max_idle_conns != 0) {
-               srv->curr_idle_thr = calloc(global.nbthread, sizeof(*srv->curr_idle_thr));
+               srv->curr_idle_thr = ha_aligned_zalloc(64, global.nbthread * sizeof(*srv->curr_idle_thr));
                if (!srv->curr_idle_thr) {
                        ha_alert("memory error during idle conn list init for %s/%s server\n",
                                 srv->proxy->id, srv->id);
@@ -5918,8 +5918,8 @@ static int srv_init_per_thr(struct server *srv)
 {
        int i;
 
-       srv->per_thr = calloc(global.nbthread, sizeof(*srv->per_thr));
-       srv->per_tgrp = calloc(global.nbtgroups, sizeof(*srv->per_tgrp));
+       srv->per_thr = ha_aligned_zalloc(64, global.nbthread * sizeof(*srv->per_thr));
+       srv->per_tgrp = ha_aligned_zalloc(64, global.nbtgroups * sizeof(*srv->per_tgrp));
        if (!srv->per_thr || !srv->per_tgrp)
                return -1;