mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-07 07:37:02 +02:00
MINOR: proxy: replace the pendconns-related stuff with a struct queue
All three elements (pendconns, nbpend, queue_idx) were moved to struct queue.
This commit is contained in:
parent
eea3817a47
commit
7f3c1df248
@ -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 @@ struct proxy {
|
||||
__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 */
|
||||
|
@ -87,7 +87,7 @@ static inline int server_has_room(const struct server *s) {
|
||||
* 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)));
|
||||
}
|
||||
|
||||
|
@ -651,7 +651,7 @@ int assign_server(struct stream *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
|
||||
|
@ -993,7 +993,7 @@ int httpchk_build_status_header(struct server *s, struct buffer *buf)
|
||||
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) &&
|
||||
|
@ -1727,7 +1727,7 @@ spoe_handle_processing_appctx(struct appctx *appctx)
|
||||
* 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;
|
||||
|
@ -915,19 +915,19 @@ static void sig_dump_state(struct sig_handler *sh)
|
||||
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);
|
||||
|
@ -1292,7 +1292,7 @@ void init_new_proxy(struct proxy *p)
|
||||
{
|
||||
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);
|
||||
|
22
src/queue.c
22
src/queue.c
@ -146,7 +146,7 @@ static void __pendconn_unlink_srv(struct pendconn *p)
|
||||
*/
|
||||
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 @@ void pendconn_unlink(struct pendconn *p)
|
||||
}
|
||||
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 @@ static struct pendconn *pendconn_process_next_strm(struct server *srv, struct pr
|
||||
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 @@ static struct pendconn *pendconn_process_next_strm(struct server *srv, struct pr
|
||||
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 @@ struct pendconn *pendconn_add(struct stream *strm)
|
||||
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 @@ struct pendconn *pendconn_add(struct stream *strm)
|
||||
__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 @@ int pendconn_grab_from_px(struct server *s)
|
||||
|
||||
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 @@ int pendconn_grab_from_px(struct server *s)
|
||||
}
|
||||
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;
|
||||
|
@ -2555,7 +2555,7 @@ int stats_fill_be_stats(struct proxy *px, int flags, struct field *stats, int le
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user