]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: proxy: replace the pendconns-related stuff with a struct queue
authorWilly Tarreau <w@1wt.eu>
Fri, 18 Jun 2021 07:22:21 +0000 (09:22 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 22 Jun 2021 16:43:14 +0000 (18:43 +0200)
All three elements (pendconns, nbpend, queue_idx) were moved to struct
queue.

include/haproxy/proxy-t.h
include/haproxy/queue.h
src/backend.c
src/check.c
src/flt_spoe.c
src/haproxy.c
src/proxy.c
src/queue.c
src/stats.c

index 8040ba885a74c3f030cd1b31f5a3e6d21e621cb6..63c0790876cf74e488a710fcd1b713b57169c94d 100644 (file)
@@ -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 */
index a5d52b3fbdafc4bf572e50b7602a1d037230627e..3c6ebe89b543887ba786791e53e372bfc509c235 100644 (file)
@@ -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)));
 }
 
index 7b14df752d472c8e800b06f48d0b38ce1db42c18..1bd40fbaa6f56448d8ab3449f8c4223e847a5ded 100644 (file)
@@ -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
index cb8545bf732eb16ab447250616ad73484217112e..68cb1c3582b6735f91b1eb64b91483980ba1179c 100644 (file)
@@ -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) &&
index 3bcd6b1464f015cb6575f689aa33bf48cdfabdad..743565d61110ee9a9f35dab4404819ffa103d1d0 100644 (file)
@@ -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;
index 7e0141335ef444dc536016f45b9d6b93874916fb..82efcd23e93b7ca2bae1d29aef393fb8fbe0b6d3 100644 (file)
@@ -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);
index 5a7f103856b607ffdd72663420c6d99e09b665d0..f6d0442f166cb2d69cbdbfa4b01fb96ff83eb2ea 100644 (file)
@@ -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);
index c45db0db2199deb872bcd4313c793386109fb148..40fabfc95ceee191d888548c8bee091ed3e2411f 100644 (file)
@@ -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;
index 0b743d18997a858d8916841d70fd33efac6c337a..c8b5fb1429b31aec11a10f1713392df5dfa8631e 100644 (file)
@@ -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);