]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: checks: start the checks in sleeping state
authorWilly Tarreau <w@1wt.eu>
Thu, 17 Aug 2023 14:09:05 +0000 (16:09 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 1 Sep 2023 06:26:06 +0000 (08:26 +0200)
The CHK_ST_SLEEPING state was introduced by commit d114f4a68 ("MEDIUM:
checks: spread the checks load over random threads") to indicate that
a check was not currently bound to a thread and that it could easily
be migrated to any other thread. However it did not start the checks
in this state, meaning that they were not redispatchable on startup.

Sometimes under heavy load (e.g. when using SSL checks with OpenSSL 3.0)
the cost of setting up new connections is so high that some threads may
experience connection timeouts on startup. In this case it's better if
they can transfer their excess load to other idle threads. By just
marking the check as sleeping upon startup, we can do this and
significantly reduce the number of failed initial checks.

include/haproxy/check-t.h
src/check.c

index 5b80189ee2fcbb3294ce8c5a7704d4eeb2f3c9fc..26290b44bc9c536c6adfb6e67fe0693dc3db97c4 100644 (file)
@@ -56,7 +56,7 @@ enum chk_result {
 #define CHK_ST_OUT_ALLOC        0x0080  /* check blocked waiting for output buffer allocation */
 #define CHK_ST_CLOSE_CONN       0x0100  /* check is waiting that the connection gets closed */
 #define CHK_ST_PURGE            0x0200  /* check must be freed */
-#define CHK_ST_SLEEPING         0x0400  /* check was sleeping */
+#define CHK_ST_SLEEPING         0x0400  /* check was sleeping, i.e. not currently bound to a thread */
 #define CHK_ST_FASTINTER        0x0800  /* force fastinter check */
 
 /* check status */
index 7359c2574da09370a2eb71baa5fa677bdb044197..fce152a96e0833c276a2bed3474d3e79dadbde5a 100644 (file)
@@ -1754,7 +1754,7 @@ int init_srv_check(struct server *srv)
                ret |= ERR_ALERT | ERR_ABORT;
                goto out;
        }
-       srv->check.state |= CHK_ST_CONFIGURED | CHK_ST_ENABLED;
+       srv->check.state |= CHK_ST_CONFIGURED | CHK_ST_ENABLED | CHK_ST_SLEEPING;
        srv_take(srv);
 
        /* Only increment maxsock for servers from the configuration. Dynamic
@@ -1817,7 +1817,7 @@ int init_srv_agent_check(struct server *srv)
        if (!srv->agent.inter)
                srv->agent.inter = srv->check.inter;
 
-       srv->agent.state |= CHK_ST_CONFIGURED | CHK_ST_ENABLED | CHK_ST_AGENT;
+       srv->agent.state |= CHK_ST_CONFIGURED | CHK_ST_ENABLED | CHK_ST_SLEEPING | CHK_ST_AGENT;
        srv_take(srv);
 
        /* Only increment maxsock for servers from the configuration. Dynamic