From: Amaury Denoyelle Date: Mon, 29 Apr 2024 14:05:27 +0000 (+0200) Subject: MINOR: counters: move freq-ctr from proxy/server into counters struct X-Git-Tag: v3.0-dev10~20 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=639e73f8f29859efb4ce7adc712aeba1685a57c0;p=thirdparty%2Fhaproxy.git MINOR: counters: move freq-ctr from proxy/server into counters struct Move freq-ctr defined in proxy or server structures into their dedicated fe_counters/be_counters struct. Functionnaly no change here. This commit will allow to convert rate stats column to generic one, which is mandatory to manipulate them in the stats-file. --- diff --git a/include/haproxy/counters-t.h b/include/haproxy/counters-t.h index 8ba6322649..eb1ce66d28 100644 --- a/include/haproxy/counters-t.h +++ b/include/haproxy/counters-t.h @@ -23,6 +23,8 @@ #ifndef _HAPROXY_COUNTERS_T_H #define _HAPROXY_COUNTERS_T_H +#include + /* counters used by listeners and frontends */ struct fe_counters { unsigned int conn_max; /* max # of active sessions */ @@ -63,6 +65,10 @@ struct fe_counters { long long cache_hits; /* cache hits */ } http; } p; /* protocol-specific stats */ + + struct freq_ctr sess_per_sec; /* sessions per second on this server */ + struct freq_ctr req_per_sec; /* HTTP requests per second on the frontend */ + struct freq_ctr conn_per_sec; /* received connections per second on the frontend */ }; /* counters used by servers and backends */ @@ -115,6 +121,8 @@ struct be_counters { long long cache_hits; /* cache hits */ } http; } p; /* protocol-specific stats */ + + struct freq_ctr sess_per_sec; /* sessions per second on this server */ }; #endif /* _HAPROXY_COUNTERS_T_H */ diff --git a/include/haproxy/proxy-t.h b/include/haproxy/proxy-t.h index eaeb06c2fc..7695b4ef36 100644 --- a/include/haproxy/proxy-t.h +++ b/include/haproxy/proxy-t.h @@ -34,7 +34,6 @@ #include #include #include -#include #include #include #include @@ -354,10 +353,6 @@ struct proxy { struct queue queue; /* queued requests (pendconns) */ int totpend; /* total number of pending connections on this instance (for stats) */ unsigned int feconn, beconn; /* # of active frontend and backends streams */ - struct freq_ctr fe_req_per_sec; /* HTTP requests per second on the frontend */ - struct freq_ctr fe_conn_per_sec; /* received connections per second on the frontend */ - struct freq_ctr fe_sess_per_sec; /* accepted sessions per second on the frontend (after tcp rules) */ - struct freq_ctr be_sess_per_sec; /* sessions per second on the backend */ unsigned int fe_sps_lim; /* limit on new sessions per second on the frontend */ unsigned int fullconn; /* #conns on backend above which servers are used at full load */ unsigned int tot_fe_maxconn; /* #maxconn of frontends linked to that backend, it is used to compute fullconn */ diff --git a/include/haproxy/proxy.h b/include/haproxy/proxy.h index c3ab1701b8..974c78aea1 100644 --- a/include/haproxy/proxy.h +++ b/include/haproxy/proxy.h @@ -134,7 +134,7 @@ static inline void proxy_inc_fe_conn_ctr(struct listener *l, struct proxy *fe) if (l && l->counters) _HA_ATOMIC_INC(&l->counters->cum_conn); HA_ATOMIC_UPDATE_MAX(&fe->fe_counters.cps_max, - update_freq_ctr(&fe->fe_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 */ @@ -145,7 +145,7 @@ static inline void proxy_inc_fe_sess_ctr(struct listener *l, struct proxy *fe) if (l && l->counters) _HA_ATOMIC_INC(&l->counters->cum_sess); HA_ATOMIC_UPDATE_MAX(&fe->fe_counters.sps_max, - update_freq_ctr(&fe->fe_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. @@ -168,7 +168,7 @@ static inline void proxy_inc_be_ctr(struct proxy *be) { _HA_ATOMIC_INC(&be->be_counters.cum_sess); HA_ATOMIC_UPDATE_MAX(&be->be_counters.sps_max, - update_freq_ctr(&be->be_sess_per_sec, 1)); + update_freq_ctr(&be->be_counters.sess_per_sec, 1)); } /* increase the number of cumulated requests on the designated frontend. @@ -185,7 +185,7 @@ static inline void proxy_inc_fe_req_ctr(struct listener *l, struct proxy *fe, if (l && l->counters) _HA_ATOMIC_INC(&l->counters->p.http.cum_req[http_ver]); HA_ATOMIC_UPDATE_MAX(&fe->fe_counters.p.http.rps_max, - update_freq_ctr(&fe->fe_req_per_sec, 1)); + update_freq_ctr(&fe->fe_counters.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-t.h b/include/haproxy/server-t.h index 3bc2371e15..b6ff41a9cf 100644 --- a/include/haproxy/server-t.h +++ b/include/haproxy/server-t.h @@ -31,7 +31,6 @@ #include #include #include -#include #include #include #include @@ -366,7 +365,6 @@ struct server { int cur_sess; /* number of currently active sessions (including syn_sent) */ int served; /* # of active sessions currently being served (ie not pending) */ int consecutive_errors; /* current number of consecutive errors */ - struct freq_ctr sess_per_sec; /* sessions per second on this server */ struct be_counters counters; /* statistics counters */ /* Below are some relatively stable settings, only changed under the lock */ diff --git a/include/haproxy/server.h b/include/haproxy/server.h index cb1c3c5494..4d27e769ff 100644 --- a/include/haproxy/server.h +++ b/include/haproxy/server.h @@ -181,7 +181,7 @@ static inline void srv_inc_sess_ctr(struct server *s) { _HA_ATOMIC_INC(&s->counters.cum_sess); HA_ATOMIC_UPDATE_MAX(&s->counters.sps_max, - update_freq_ctr(&s->sess_per_sec, 1)); + update_freq_ctr(&s->counters.sess_per_sec, 1)); } /* set the time of last session on the designated server */ diff --git a/src/backend.c b/src/backend.c index 57b9ee34f1..cfe1add5a6 100644 --- a/src/backend.c +++ b/src/backend.c @@ -3080,7 +3080,7 @@ smp_fetch_be_sess_rate(const struct arg *args, struct sample *smp, const char *k smp->flags = SMP_F_VOL_TEST; smp->data.type = SMP_T_SINT; - smp->data.u.sint = read_freq_ctr(&px->be_sess_per_sec); + smp->data.u.sint = read_freq_ctr(&px->be_counters.sess_per_sec); return 1; } @@ -3263,7 +3263,7 @@ smp_fetch_srv_sess_rate(const struct arg *args, struct sample *smp, const char * { smp->flags = SMP_F_VOL_TEST; smp->data.type = SMP_T_SINT; - smp->data.u.sint = read_freq_ctr(&args->data.srv->sess_per_sec); + smp->data.u.sint = read_freq_ctr(&args->data.srv->counters.sess_per_sec); return 1; } diff --git a/src/frontend.c b/src/frontend.c index e9b3bc0694..3b3bcbb163 100644 --- a/src/frontend.c +++ b/src/frontend.c @@ -252,7 +252,7 @@ smp_fetch_fe_req_rate(const struct arg *args, struct sample *smp, const char *kw smp->flags = SMP_F_VOL_TEST; smp->data.type = SMP_T_SINT; - smp->data.u.sint = read_freq_ctr(&px->fe_req_per_sec); + smp->data.u.sint = read_freq_ctr(&px->fe_counters.req_per_sec); return 1; } @@ -272,7 +272,7 @@ smp_fetch_fe_sess_rate(const struct arg *args, struct sample *smp, const char *k smp->flags = SMP_F_VOL_TEST; smp->data.type = SMP_T_SINT; - smp->data.u.sint = read_freq_ctr(&px->fe_sess_per_sec); + smp->data.u.sint = read_freq_ctr(&px->fe_counters.sess_per_sec); return 1; } diff --git a/src/listener.c b/src/listener.c index 01740f003d..a3485580b3 100644 --- a/src/listener.c +++ b/src/listener.c @@ -1070,11 +1070,11 @@ void listener_accept(struct listener *l) } #endif if (p && p->fe_sps_lim) { - int max = freq_ctr_remain(&p->fe_sess_per_sec, p->fe_sps_lim, 0); + int max = freq_ctr_remain(&p->fe_counters.sess_per_sec, p->fe_sps_lim, 0); if (unlikely(!max)) { /* frontend accept rate limit was reached */ - expire = tick_add(now_ms, next_event_delay(&p->fe_sess_per_sec, p->fe_sps_lim, 0)); + expire = tick_add(now_ms, next_event_delay(&p->fe_counters.sess_per_sec, p->fe_sps_lim, 0)); goto limit_proxy; } @@ -1545,7 +1545,7 @@ void listener_accept(struct listener *l) dequeue_all_listeners(); if (p && !MT_LIST_ISEMPTY(&p->listener_queue) && - (!p->fe_sps_lim || freq_ctr_remain(&p->fe_sess_per_sec, p->fe_sps_lim, 0) > 0)) + (!p->fe_sps_lim || freq_ctr_remain(&p->fe_counters.sess_per_sec, p->fe_sps_lim, 0) > 0)) dequeue_proxy_listeners(p); } return; @@ -1604,14 +1604,14 @@ void listener_release(struct listener *l) dequeue_all_listeners(); if (fe && !MT_LIST_ISEMPTY(&fe->listener_queue) && - (!fe->fe_sps_lim || freq_ctr_remain(&fe->fe_sess_per_sec, fe->fe_sps_lim, 0) > 0)) + (!fe->fe_sps_lim || freq_ctr_remain(&fe->fe_counters.sess_per_sec, fe->fe_sps_lim, 0) > 0)) dequeue_proxy_listeners(fe); else { unsigned int wait; int expire = TICK_ETERNITY; if (fe->task && fe->fe_sps_lim && - (wait = next_event_delay(&fe->fe_sess_per_sec,fe->fe_sps_lim, 0))) { + (wait = next_event_delay(&fe->fe_counters.sess_per_sec,fe->fe_sps_lim, 0))) { /* we're blocking because a limit was reached on the number of * requests/s on the frontend. We want to re-check ASAP, which * means in 1 ms before estimated expiration date, because the diff --git a/src/proxy.c b/src/proxy.c index e5ba7bf120..6fd123638f 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -1980,7 +1980,7 @@ struct task *manage_proxy(struct task *t, void *context, unsigned int state) goto out; if (p->fe_sps_lim && - (wait = next_event_delay(&p->fe_sess_per_sec, p->fe_sps_lim, 0))) { + (wait = next_event_delay(&p->fe_counters.sess_per_sec, p->fe_sps_lim, 0))) { /* we're blocking because a limit was reached on the number of * requests/s on the frontend. We want to re-check ASAP, which * means in 1 ms before estimated expiration date, because the diff --git a/src/stats.c b/src/stats.c index 5ada0503ee..65b701fdb6 100644 --- a/src/stats.c +++ b/src/stats.c @@ -877,7 +877,7 @@ int stats_fill_fe_line(struct proxy *px, int flags, struct field *line, int len, field = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_FE); break; case ST_I_PX_RATE: - field = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_sess_per_sec)); + field = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_counters.sess_per_sec)); break; case ST_I_PX_RATE_LIM: field = mkf_u32(FO_CONFIG|FN_LIMIT, px->fe_sps_lim); @@ -886,13 +886,13 @@ int stats_fill_fe_line(struct proxy *px, int flags, struct field *line, int len, field = mkf_u32(FN_MAX, px->fe_counters.sps_max); break; case ST_I_PX_REQ_RATE: - field = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_req_per_sec)); + field = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_counters.req_per_sec)); break; case ST_I_PX_REQ_RATE_MAX: field = mkf_u32(FN_MAX, px->fe_counters.p.http.rps_max); break; case ST_I_PX_CONN_RATE: - field = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_conn_per_sec)); + field = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_counters.conn_per_sec)); break; case ST_I_PX_CONN_RATE_MAX: field = mkf_u32(FN_MAX, px->fe_counters.cps_max); @@ -1364,7 +1364,7 @@ int stats_fill_sv_line(struct proxy *px, struct server *sv, int flags, field = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_SV); break; case ST_I_PX_RATE: - field = mkf_u32(FN_RATE, read_freq_ctr(&sv->sess_per_sec)); + field = mkf_u32(FN_RATE, read_freq_ctr(&sv->counters.sess_per_sec)); break; case ST_I_PX_RATE_MAX: field = mkf_u32(FN_MAX, sv->counters.sps_max); @@ -1710,7 +1710,7 @@ int stats_fill_be_line(struct proxy *px, int flags, struct field *line, int len, field = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_BE); break; case ST_I_PX_RATE: - field = mkf_u32(0, read_freq_ctr(&px->be_sess_per_sec)); + field = mkf_u32(0, read_freq_ctr(&px->be_counters.sess_per_sec)); break; case ST_I_PX_RATE_MAX: field = mkf_u32(0, px->be_counters.sps_max);