From: Willy Tarreau Date: Thu, 22 Oct 2020 15:41:45 +0000 (+0200) Subject: MINOR: leastconn: take the queue length into account when queuing servers X-Git-Tag: v2.3-dev8~14 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8c855f6cff6864be423e9c18d98b0c2ac99486fb;p=thirdparty%2Fhaproxy.git MINOR: leastconn: take the queue length into account when queuing servers When servers are queued into the leastconn tree, it's important to also consider their queue length. There could be some servers with lots of queued requests that we don't want to hammer with extra connections. In order not to add extra stress to the LB algorithm, we don't update the value when adding to the queue, only when updating the connection count (i.e. picking from the queue or releasing a connection). This will be sufficient to significantly improve the fairness in such situations. --- diff --git a/doc/configuration.txt b/doc/configuration.txt index ea6c589c4e..6116f25d35 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -3205,7 +3205,9 @@ balance url_param [check_post] expected, such as LDAP, SQL, TSE, etc... but is not very well suited for protocols using short sessions such as HTTP. This algorithm is dynamic, which means that server weights may be - adjusted on the fly for slow starts for instance. + adjusted on the fly for slow starts for instance. It will + also consider the number of queued connections in addition to + the established ones in order to minimize queuing. first The first server with available connection slots receives the connection. The servers are chosen from the lowest numeric diff --git a/src/lb_fwlc.c b/src/lb_fwlc.c index 78a38a434f..c7e0dd8017 100644 --- a/src/lb_fwlc.c +++ b/src/lb_fwlc.c @@ -51,7 +51,9 @@ static inline void fwlc_dequeue_srv(struct server *s) */ static inline void fwlc_queue_srv(struct server *s) { - s->lb_node.key = s->served ? (s->served + 1) * SRV_EWGHT_MAX / s->next_eweight : 0; + unsigned int inflight = s->served + s->nbpend; + + s->lb_node.key = inflight ? (inflight + 1) * SRV_EWGHT_MAX / s->next_eweight : 0; eb32_insert(s->lb_tree, &s->lb_node); }