MINOR: proxy: replace the pendconns-related stuff with a struct queue
All three elements (pendconns, nbpend, queue_idx) were moved to struct
queue.
diff --git a/include/haproxy/proxy-t.h b/include/haproxy/proxy-t.h
index 8040ba8..63c0790 100644
--- a/include/haproxy/proxy-t.h
+++ b/include/haproxy/proxy-t.h
@@ -37,6 +37,7 @@
#include <haproxy/counters-t.h>
#include <haproxy/freq_ctr-t.h>
#include <haproxy/obj_type-t.h>
+#include <haproxy/queue-t.h>
#include <haproxy/server-t.h>
#include <haproxy/stats-t.h>
#include <haproxy/tcpcheck-t.h>
@@ -332,10 +333,8 @@
__decl_thread(HA_RWLOCK_T lock); /* may be taken under the server's lock */
char *id, *desc; /* proxy id (name) and description */
- struct eb_root pendconns; /* pending connections with no server assigned yet */
- int nbpend; /* number of pending connections with no server assigned yet */
+ struct queue queue; /* queued requests (pendconns) */
int totpend; /* total number of pending connections on this instance (for stats) */
- unsigned int queue_idx; /* number of pending connections which have been de-queued */
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 */
diff --git a/include/haproxy/queue.h b/include/haproxy/queue.h
index a5d52b3..3c6ebe8 100644
--- a/include/haproxy/queue.h
+++ b/include/haproxy/queue.h
@@ -87,7 +87,7 @@
* for and if/else usage.
*/
static inline int may_dequeue_tasks(const struct server *s, const struct proxy *p) {
- return (s && (s->nbpend || (p->nbpend && srv_currently_usable(s))) &&
+ return (s && (s->nbpend || (p->queue.length && srv_currently_usable(s))) &&
(!s->maxconn || s->cur_sess < srv_dynamic_maxconn(s)));
}
diff --git a/src/backend.c b/src/backend.c
index 7b14df7..1bd40fb 100644
--- a/src/backend.c
+++ b/src/backend.c
@@ -651,7 +651,7 @@
/* if there's some queue on the backend, with certain algos we
* know it's because all servers are full.
*/
- if (s->be->nbpend && s->be->nbpend != s->be->beconn &&
+ if (s->be->queue.length && s->be->queue.length != s->be->beconn &&
(((s->be->lbprm.algo & (BE_LB_KIND|BE_LB_NEED|BE_LB_PARM)) == BE_LB_ALGO_FAS)|| // first
((s->be->lbprm.algo & (BE_LB_KIND|BE_LB_NEED|BE_LB_PARM)) == BE_LB_ALGO_RR) || // roundrobin
((s->be->lbprm.algo & (BE_LB_KIND|BE_LB_NEED|BE_LB_PARM)) == BE_LB_ALGO_SRR))) { // static-rr
diff --git a/src/check.c b/src/check.c
index cb8545b..68cb1c3 100644
--- a/src/check.c
+++ b/src/check.c
@@ -993,7 +993,7 @@
global.node,
(s->cur_eweight * s->proxy->lbprm.wmult + s->proxy->lbprm.wdiv - 1) / s->proxy->lbprm.wdiv,
(s->proxy->lbprm.tot_weight * s->proxy->lbprm.wmult + s->proxy->lbprm.wdiv - 1) / s->proxy->lbprm.wdiv,
- s->cur_sess, s->proxy->beconn - s->proxy->nbpend,
+ s->cur_sess, s->proxy->beconn - s->proxy->queue.length,
s->nbpend);
if ((s->cur_state == SRV_ST_STARTING) &&
diff --git a/src/flt_spoe.c b/src/flt_spoe.c
index 3bcd6b1..743565d 100644
--- a/src/flt_spoe.c
+++ b/src/flt_spoe.c
@@ -1727,7 +1727,7 @@
* applet in the idle list.
*/
if (global.nbthread > 1 &&
- (agent->b.be->nbpend ||
+ (agent->b.be->queue.length ||
(srv && (srv->nbpend || (srv->maxconn && srv->served >=srv_dynamic_maxconn(srv)))))) {
SPOE_APPCTX(appctx)->status_code = SPOE_FRM_ERR_NONE;
appctx->st0 = SPOE_APPCTX_ST_DISCONNECT;
diff --git a/src/haproxy.c b/src/haproxy.c
index 7e01413..82efcd2 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -915,19 +915,19 @@
chunk_printf(&trash,
"SIGHUP: Proxy %s has no servers. Conn: act(FE+BE): %d+%d, %d pend (%d unass), tot(FE+BE): %lld+%lld.",
p->id,
- p->feconn, p->beconn, p->totpend, p->nbpend, p->fe_counters.cum_conn, p->be_counters.cum_conn);
+ p->feconn, p->beconn, p->totpend, p->queue.length, p->fe_counters.cum_conn, p->be_counters.cum_conn);
} else if (p->srv_act == 0) {
chunk_printf(&trash,
"SIGHUP: Proxy %s %s ! Conn: act(FE+BE): %d+%d, %d pend (%d unass), tot(FE+BE): %lld+%lld.",
p->id,
(p->srv_bck) ? "is running on backup servers" : "has no server available",
- p->feconn, p->beconn, p->totpend, p->nbpend, p->fe_counters.cum_conn, p->be_counters.cum_conn);
+ p->feconn, p->beconn, p->totpend, p->queue.length, p->fe_counters.cum_conn, p->be_counters.cum_conn);
} else {
chunk_printf(&trash,
"SIGHUP: Proxy %s has %d active servers and %d backup servers available."
" Conn: act(FE+BE): %d+%d, %d pend (%d unass), tot(FE+BE): %lld+%lld.",
p->id, p->srv_act, p->srv_bck,
- p->feconn, p->beconn, p->totpend, p->nbpend, p->fe_counters.cum_conn, p->be_counters.cum_conn);
+ p->feconn, p->beconn, p->totpend, p->queue.length, p->fe_counters.cum_conn, p->be_counters.cum_conn);
}
ha_warning("%s\n", trash.area);
send_log(p, LOG_NOTICE, "%s\n", trash.area);
diff --git a/src/proxy.c b/src/proxy.c
index 5a7f103..f6d0442 100644
--- a/src/proxy.c
+++ b/src/proxy.c
@@ -1292,7 +1292,7 @@
{
memset(p, 0, sizeof(struct proxy));
p->obj_type = OBJ_TYPE_PROXY;
- p->pendconns = EB_ROOT;
+ p->queue.head = EB_ROOT;
LIST_INIT(&p->acl);
LIST_INIT(&p->http_req_rules);
LIST_INIT(&p->http_res_rules);
diff --git a/src/queue.c b/src/queue.c
index c45db0d..40fabfc 100644
--- a/src/queue.c
+++ b/src/queue.c
@@ -146,7 +146,7 @@
*/
static void __pendconn_unlink_prx(struct pendconn *p)
{
- p->strm->logs.prx_queue_pos += p->px->queue_idx - p->queue_idx;
+ p->strm->logs.prx_queue_pos += p->px->queue.idx - p->queue_idx;
eb32_delete(&p->node);
}
@@ -207,7 +207,7 @@
}
HA_RWLOCK_WRUNLOCK(PROXY_LOCK, &p->px->lock);
if (done) {
- _HA_ATOMIC_DEC(&p->px->nbpend);
+ _HA_ATOMIC_DEC(&p->px->queue.length);
_HA_ATOMIC_DEC(&p->px->totpend);
}
}
@@ -277,11 +277,11 @@
p = pendconn_first(&srv->pendconns);
pp = NULL;
- if (srv_currently_usable(rsrv) && px->nbpend &&
+ if (srv_currently_usable(rsrv) && px->queue.length &&
(!(srv->flags & SRV_F_BACKUP) ||
(!px->srv_act &&
(srv == px->lbprm.fbck || (px->options & PR_O_USE_ALL_BK)))))
- pp = pendconn_first(&px->pendconns);
+ pp = pendconn_first(&px->queue.head);
if (!p && !pp)
return NULL;
@@ -313,9 +313,9 @@
use_pp:
/* Let's switch from the server pendconn to the proxy pendconn */
__pendconn_unlink_prx(pp);
- _HA_ATOMIC_DEC(&px->nbpend);
+ _HA_ATOMIC_DEC(&px->queue.length);
_HA_ATOMIC_DEC(&px->totpend);
- px->queue_idx++;
+ px->queue.idx++;
p = pp;
goto unlinked;
use_p:
@@ -432,7 +432,7 @@
else {
unsigned int old_max, new_max;
- new_max = _HA_ATOMIC_ADD_FETCH(&px->nbpend, 1);
+ new_max = _HA_ATOMIC_ADD_FETCH(&px->queue.length, 1);
old_max = px->be_counters.nbpend_max;
while (new_max > old_max) {
if (likely(_HA_ATOMIC_CAS(&px->be_counters.nbpend_max, &old_max, new_max)))
@@ -441,8 +441,8 @@
__ha_barrier_atomic_store();
HA_RWLOCK_WRLOCK(PROXY_LOCK, &p->px->lock);
- p->queue_idx = px->queue_idx - 1; // for increment
- eb32_insert(&px->pendconns, &p->node);
+ p->queue_idx = px->queue.idx - 1; // for increment
+ eb32_insert(&px->queue.head, &p->node);
HA_RWLOCK_WRUNLOCK(PROXY_LOCK, &p->px->lock);
}
@@ -511,7 +511,7 @@
HA_RWLOCK_WRLOCK(PROXY_LOCK, &s->proxy->lock);
maxconn = srv_dynamic_maxconn(s);
- while ((p = pendconn_first(&s->proxy->pendconns))) {
+ while ((p = pendconn_first(&s->proxy->queue.head))) {
if (s->maxconn && s->served + xferred >= maxconn)
break;
@@ -523,7 +523,7 @@
}
HA_RWLOCK_WRUNLOCK(PROXY_LOCK, &s->proxy->lock);
if (xferred) {
- _HA_ATOMIC_SUB(&s->proxy->nbpend, xferred);
+ _HA_ATOMIC_SUB(&s->proxy->queue.length, xferred);
_HA_ATOMIC_SUB(&s->proxy->totpend, xferred);
}
return xferred;
diff --git a/src/stats.c b/src/stats.c
index 0b743d1..c8b5fb1 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -2555,7 +2555,7 @@
metric = mkf_str(FO_CONFIG|FS_SERVICE, proxy_mode_str(px->mode));
break;
case ST_F_QCUR:
- metric = mkf_u32(0, px->nbpend);
+ metric = mkf_u32(0, px->queue.length);
break;
case ST_F_QMAX:
metric = mkf_u32(FN_MAX, px->be_counters.nbpend_max);