#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>
__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 */
* 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)));
}
/* 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
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) &&
* 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;
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);
{
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);
*/
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);
}
}
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);
}
}
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;
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:
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)))
__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);
}
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;
}
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;
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);