]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: servers: Don't update last_sess if it did not change
authorOlivier Houchard <ohouchard@haproxy.com>
Wed, 1 Apr 2026 13:08:26 +0000 (15:08 +0200)
committerOlivier Houchard <cognet@ci0.org>
Wed, 1 Apr 2026 13:06:55 +0000 (15:06 +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/server.h

index 6294bf246f8ea03aed4fdc6e4216d754f0f72aa2..6bdd823f229ff16e23aa3af92a7280f0fa099a06 100644 (file)
@@ -220,8 +220,12 @@ static inline void srv_inc_sess_ctr(struct server *s)
 /* set the time of last session on the designated server */
 static inline void srv_set_sess_last(struct server *s)
 {
-       if (s->counters.shared.tg)
-               HA_ATOMIC_STORE(&s->counters.shared.tg[tgid - 1]->last_sess,  ns_to_sec(now_ns));
+       if (s->counters.shared.tg) {
+               uint now_sec = ns_to_sec(now_ms);
+
+               if (HA_ATOMIC_LOAD(&s->counters.shared.tg[tgid - 1]->last_sess) != now_sec)
+                       HA_ATOMIC_STORE(&s->counters.shared.tg[tgid - 1]->last_sess, now_sec);
+       }
 }
 
 /* returns the current server throttle rate between 0 and 100% */