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.
This commit is contained in:
Aurelien DARRAGON 2025-05-28 12:00:49 +02:00
parent b72a8bb138
commit 12c3ffbb48
3 changed files with 15 additions and 5 deletions

View File

@ -88,10 +88,13 @@ struct fe_counters {
unsigned int cps_max; /* maximum of new connections received per second */ unsigned int cps_max; /* maximum of new connections received per second */
unsigned int sps_max; /* maximum of new connections accepted per second (sessions) */ 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 { union {
struct { struct {
unsigned int rps_max; /* maximum of new HTTP requests second observed */ 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; } http;
} p; /* protocol-specific stats */ } 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 nbpend_max; /* max number of pending connections with no server assigned yet */
unsigned int cur_sess_max; /* max number of currently active sessions */ 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 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 */ unsigned int qtime_max, ctime_max, dtime_max, ttime_max; /* maximum of conn_time, queue_time, data_time, total_time observed */

View 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); _HA_ATOMIC_INC(&fe->fe_counters.shared->cum_conn);
if (l && l->counters) if (l && l->counters)
_HA_ATOMIC_INC(&l->counters->shared->cum_conn); _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, 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 */ /* 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); _HA_ATOMIC_INC(&fe->fe_counters.shared->cum_sess);
if (l && l->counters) if (l && l->counters)
_HA_ATOMIC_INC(&l->counters->shared->cum_sess); _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, 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. /* 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) static inline void proxy_inc_be_ctr(struct proxy *be)
{ {
_HA_ATOMIC_INC(&be->be_counters.shared->cum_sess); _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, 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. /* 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]); _HA_ATOMIC_INC(&fe->fe_counters.shared->p.http.cum_req[http_ver]);
if (l && l->counters) if (l && l->counters)
_HA_ATOMIC_INC(&l->counters->shared->p.http.cum_req[http_ver]); _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, 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 */ /* Returns non-zero if the proxy is configured to retry a request if we got that status, 0 otherwise */

View 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) static inline void srv_inc_sess_ctr(struct server *s)
{ {
_HA_ATOMIC_INC(&s->counters.shared->cum_sess); _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, 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 */ /* set the time of last session on the designated server */