]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: backends: Don't update last_sess if it did not change
authorOlivier Houchard <ohouchard@haproxy.com>
Wed, 1 Apr 2026 13:01:09 +0000 (15:01 +0200)
committerOlivier Houchard <cognet@ci0.org>
Wed, 1 Apr 2026 12:58:59 +0000 (14:58 +0200)
Check that last_sess actually changed before attempting to set it, as it
should only change once every second, that will avoid a lot of atomic
writes on a busy cache line.

include/haproxy/backend.h

index 6930ff256d3f5b7533dcf29a00e7ed94f389792b..263a2e2c23f5354a3c2167d5a4178b37022d7c6d 100644 (file)
@@ -99,8 +99,11 @@ static inline int be_is_eligible(const struct proxy *be)
 /* set the time of last session on the backend */
 static inline void be_set_sess_last(struct proxy *be)
 {
+       uint now_sec = ns_to_sec(now_ns);
+
        if (be->be_counters.shared.tg)
-               HA_ATOMIC_STORE(&be->be_counters.shared.tg[tgid - 1]->last_sess, ns_to_sec(now_ns));
+               if (HA_ATOMIC_LOAD(&be->be_counters.shared.tg[tgid - 1]->last_sess) != now_sec)
+                       HA_ATOMIC_STORE(&be->be_counters.shared.tg[tgid - 1]->last_sess, now_sec);
 }
 
 /* This function returns non-zero if the designated server will be