]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: leastconn: take the queue length into account when queuing servers
authorWilly Tarreau <w@1wt.eu>
Thu, 22 Oct 2020 15:41:45 +0000 (17:41 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 22 Oct 2020 16:30:18 +0000 (18:30 +0200)
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.

doc/configuration.txt
src/lb_fwlc.c

index ea6c589c4e3170a87ab952f8c81e859b80d47c79..6116f25d350199b4f6b887176310cda7200ea670 100644 (file)
@@ -3205,7 +3205,9 @@ balance url_param <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
index 78a38a434fea7bac6b97a319d0a4173fc200a4b6..c7e0dd80179b3ccd2e9fcef65217ff4eba8c658b 100644 (file)
@@ -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);
 }