]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: counters: add local-only internal rates to compute some maxes
authorAurelien DARRAGON <adarragon@haproxy.com>
Wed, 28 May 2025 10:00:49 +0000 (12:00 +0200)
committerAurelien DARRAGON <adarragon@haproxy.com>
Thu, 5 Jun 2025 07:59:31 +0000 (09:59 +0200)
cps_max (max new connections received per second), sps_max (max new
sessions per second) and http.rps_max (maximum new http requests per
second) all rely on shared counters (namely conn_per_sec, sess_per_sec and
http.req_per_sec). The problem is that shared counters are about to be
distributed over thread groups, and we cannot afford to compute the
total (for all thread groups) each time we update the max counters.

Instead, since such max counters (relying on shared counters) are a very
few exceptions, let's add internal (sess,conn,req) per sec freq counters
that are dedicated to cps_max, sps_max and http.rps_max computing.

Thanks to that, related *_max counters shouldn't be negatively impacted
by the thread-group distribution, yet they will not benefit from it
either. Related internal freq counters are prefixed with "_" to emphasize
the fact that they should not be used for other purpose (the shared ones,
which are about to be distributed over thread groups in upcoming commits
are still available and must be used instead). The internal ones could
eventually be removed at any time if we find another way to compute the
{cps,sps,http.rps)_max counters.

include/haproxy/counters-t.h
include/haproxy/proxy.h
include/haproxy/server.h

index 5b7842ae36ad49f57bccb5fcd3a052d855bc6a24..d9bb5cfb4443b3090262b37b3709cd7f369bc9e0 100644 (file)
@@ -88,10 +88,13 @@ struct fe_counters {
 
        unsigned int cps_max;                   /* maximum of new connections received per second */
        unsigned int sps_max;                   /* maximum of new connections accepted per second (sessions) */
+       struct freq_ctr _sess_per_sec;          /* sessions per second on this frontend, used to compute sps_max (internal use only) */
+       struct freq_ctr _conn_per_sec;          /* connections per second on this frontend, used to compute cps_max (internal use only) */
 
        union {
                struct {
                        unsigned int rps_max;   /* maximum of new HTTP requests second observed */
+                       struct freq_ctr _req_per_sec; /* HTTP requests per second on the frontend, only used to compute rps_max */
                } http;
        } p;                                    /* protocol-specific stats */
 };
@@ -136,6 +139,8 @@ struct be_counters {
        unsigned int nbpend_max;                /* max number of pending connections with no server assigned yet */
        unsigned int cur_sess_max;              /* max number of currently active sessions */
 
+       struct freq_ctr _sess_per_sec;          /* sessions per second on this frontend, used to compute sps_max (internal use only) */
+
        unsigned int q_time, c_time, d_time, t_time; /* sums of conn_time, queue_time, data_time, total_time */
        unsigned int qtime_max, ctime_max, dtime_max, ttime_max; /* maximum of conn_time, queue_time, data_time, total_time observed */
 
index e2eaa2baca9986cacc09d48e127954d50b0ab6d4..0c8d5446cc9ed1698bf559d848aa77e358bcb1da 100644 (file)
@@ -139,8 +139,9 @@ static inline void proxy_inc_fe_conn_ctr(struct listener *l, struct proxy *fe)
        _HA_ATOMIC_INC(&fe->fe_counters.shared->cum_conn);
        if (l && l->counters)
                _HA_ATOMIC_INC(&l->counters->shared->cum_conn);
+       update_freq_ctr(&fe->fe_counters.shared->conn_per_sec, 1);
        HA_ATOMIC_UPDATE_MAX(&fe->fe_counters.cps_max,
-                            update_freq_ctr(&fe->fe_counters.shared->conn_per_sec, 1));
+                            update_freq_ctr(&fe->fe_counters._conn_per_sec, 1));
 }
 
 /* increase the number of cumulated connections accepted by the designated frontend */
@@ -150,8 +151,9 @@ static inline void proxy_inc_fe_sess_ctr(struct listener *l, struct proxy *fe)
        _HA_ATOMIC_INC(&fe->fe_counters.shared->cum_sess);
        if (l && l->counters)
                _HA_ATOMIC_INC(&l->counters->shared->cum_sess);
+       update_freq_ctr(&fe->fe_counters.shared->sess_per_sec, 1);
        HA_ATOMIC_UPDATE_MAX(&fe->fe_counters.sps_max,
-                            update_freq_ctr(&fe->fe_counters.shared->sess_per_sec, 1));
+                            update_freq_ctr(&fe->fe_counters._sess_per_sec, 1));
 }
 
 /* increase the number of cumulated HTTP sessions on the designated frontend.
@@ -173,8 +175,9 @@ static inline void proxy_inc_fe_cum_sess_ver_ctr(struct listener *l, struct prox
 static inline void proxy_inc_be_ctr(struct proxy *be)
 {
        _HA_ATOMIC_INC(&be->be_counters.shared->cum_sess);
+       update_freq_ctr(&be->be_counters.shared->sess_per_sec, 1);
        HA_ATOMIC_UPDATE_MAX(&be->be_counters.sps_max,
-                            update_freq_ctr(&be->be_counters.shared->sess_per_sec, 1));
+                            update_freq_ctr(&be->be_counters._sess_per_sec, 1));
 }
 
 /* increase the number of cumulated requests on the designated frontend.
@@ -190,8 +193,9 @@ static inline void proxy_inc_fe_req_ctr(struct listener *l, struct proxy *fe,
        _HA_ATOMIC_INC(&fe->fe_counters.shared->p.http.cum_req[http_ver]);
        if (l && l->counters)
                _HA_ATOMIC_INC(&l->counters->shared->p.http.cum_req[http_ver]);
+       update_freq_ctr(&fe->fe_counters.shared->req_per_sec, 1);
        HA_ATOMIC_UPDATE_MAX(&fe->fe_counters.p.http.rps_max,
-                            update_freq_ctr(&fe->fe_counters.shared->req_per_sec, 1));
+                            update_freq_ctr(&fe->fe_counters.p.http._req_per_sec, 1));
 }
 
 /* Returns non-zero if the proxy is configured to retry a request if we got that status, 0 otherwise */
index 61ece11a2bd98c60e1b05dfeaca57bcf41ed1c07..14f8ea342152420072a1058e854de4a9d6a601b6 100644 (file)
@@ -182,8 +182,9 @@ const struct mux_ops *srv_get_ws_proto(struct server *srv);
 static inline void srv_inc_sess_ctr(struct server *s)
 {
        _HA_ATOMIC_INC(&s->counters.shared->cum_sess);
+       update_freq_ctr(&s->counters.shared->sess_per_sec, 1);
        HA_ATOMIC_UPDATE_MAX(&s->counters.sps_max,
-                            update_freq_ctr(&s->counters.shared->sess_per_sec, 1));
+                            update_freq_ctr(&s->counters._sess_per_sec, 1));
 }
 
 /* set the time of last session on the designated server */