From: Aurelien DARRAGON Date: Wed, 28 May 2025 10:00:49 +0000 (+0200) Subject: MINOR: counters: add local-only internal rates to compute some maxes X-Git-Tag: v3.3-dev1~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=12c3ffbb48cfd3f4833d7a7ad636fe50ea135e73;p=thirdparty%2Fhaproxy.git MINOR: counters: add local-only internal rates to compute some maxes 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. --- diff --git a/include/haproxy/counters-t.h b/include/haproxy/counters-t.h index 5b7842ae3..d9bb5cfb4 100644 --- a/include/haproxy/counters-t.h +++ b/include/haproxy/counters-t.h @@ -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 */ diff --git a/include/haproxy/proxy.h b/include/haproxy/proxy.h index e2eaa2bac..0c8d5446c 100644 --- a/include/haproxy/proxy.h +++ b/include/haproxy/proxy.h @@ -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 */ diff --git a/include/haproxy/server.h b/include/haproxy/server.h index 61ece11a2..14f8ea342 100644 --- a/include/haproxy/server.h +++ b/include/haproxy/server.h @@ -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 */