mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-06 07:07:04 +02:00
MEDIUM: proxy: add and use a separate last_change variable for internal use
Same motivation as previous commit, proxy last_change is "abused" because it is used for 2 different purposes, one for stats, and the other one for process-local internal use. Let's add a separate proxy-only last_change variable for internal use, and leave the last_change shared (and thread-grouped) counter for statistics.
This commit is contained in:
parent
01dfe17acf
commit
5b1480c9d4
@ -311,7 +311,7 @@ struct proxy {
|
||||
char flags; /* bit field PR_FL_* */
|
||||
enum pr_mode mode; /* mode = PR_MODE_TCP, PR_MODE_HTTP, ... */
|
||||
char cap; /* supported capabilities (PR_CAP_*) */
|
||||
/* 4-bytes hole */
|
||||
unsigned long last_change; /* internal use only: last time the proxy state was changed */
|
||||
|
||||
struct list global_list; /* list member for global proxy list */
|
||||
|
||||
|
@ -2894,6 +2894,7 @@ void back_handle_st_rdy(struct stream *s)
|
||||
*/
|
||||
void set_backend_down(struct proxy *be)
|
||||
{
|
||||
be->last_change = ns_to_sec(now_ns);
|
||||
HA_ATOMIC_STORE(&be->be_counters.shared->tg[tgid - 1]->last_change, ns_to_sec(now_ns));
|
||||
_HA_ATOMIC_INC(&be->be_counters.shared->tg[tgid - 1]->down_trans);
|
||||
|
||||
@ -2967,12 +2968,10 @@ int tcp_persist_rdp_cookie(struct stream *s, struct channel *req, int an_bit)
|
||||
}
|
||||
|
||||
int be_downtime(struct proxy *px) {
|
||||
unsigned long last_change = COUNTERS_SHARED_LAST(px->be_counters.shared->tg, last_change);
|
||||
|
||||
if (px->lbprm.tot_weight && last_change < ns_to_sec(now_ns)) // ignore negative time
|
||||
if (px->lbprm.tot_weight && px->last_change < ns_to_sec(now_ns)) // ignore negative time
|
||||
return px->down_time;
|
||||
|
||||
return ns_to_sec(now_ns) - last_change + px->down_time;
|
||||
return ns_to_sec(now_ns) - px->last_change + px->down_time;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1722,6 +1722,7 @@ int setup_new_proxy(struct proxy *px, const char *name, unsigned int cap, char *
|
||||
}
|
||||
|
||||
px->cap = cap;
|
||||
px->last_change = ns_to_sec(now_ns);
|
||||
|
||||
if (name && !(cap & PR_CAP_INT))
|
||||
proxy_store_name(px);
|
||||
|
@ -7064,13 +7064,14 @@ static void srv_update_status(struct server *s, int type, int cause)
|
||||
if (prev_srv_count && s->proxy->srv_bck == 0 && s->proxy->srv_act == 0)
|
||||
set_backend_down(s->proxy); /* backend going down */
|
||||
else if (!prev_srv_count && (s->proxy->srv_bck || s->proxy->srv_act)) {
|
||||
unsigned long last_change = COUNTERS_SHARED_LAST(s->proxy->be_counters.shared->tg, last_change);
|
||||
unsigned long last_change = s->proxy->last_change;
|
||||
|
||||
/* backend was down and is back up again:
|
||||
* no helper function, updating last_change and backend downtime stats
|
||||
*/
|
||||
if (last_change < ns_to_sec(now_ns)) // ignore negative times
|
||||
s->proxy->down_time += ns_to_sec(now_ns) - last_change;
|
||||
s->proxy->last_change = ns_to_sec(now_ns);
|
||||
HA_ATOMIC_STORE(&s->proxy->be_counters.shared->tg[tgid - 1]->last_change, ns_to_sec(now_ns));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user