From c5940392255e5a5a7eb0d27be62e155f1aec26c6 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 5 Sep 2019 17:38:40 +0200 Subject: [PATCH] BUG/MINOR: checks: do not uselessly poll for reads before the connection is up It's pointless to start to perform a recv() call on a connection that is not yet established. The only purpose used to be to subscribe but that causes many extra syscalls when we know we can do it later. This patch only attempts a read if the connection is established or if there is no write planed, since we want to be certain to be called. And in wake_srv_chk() we continue to attempt to read if the reader was not subscribed, so as to perform the first read attempt. In case a first result is provided, __event_srv_chk_r() will not do anything anyway so this is totally harmless in this case. This fix requires that commit "BUG/MINOR: checks: make __event_chk_srv_r() report success before closing" is applied before, otherwise it will break some checks (notably SSL) by doing them again after the connection is shut down. This completes the fixes on the checks described in issue #253 by roughly cutting the number of syscalls in half. It must be backported to 2.0. --- src/checks.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/checks.c b/src/checks.c index 1268cda5ee..e5dfdd73c8 100644 --- a/src/checks.c +++ b/src/checks.c @@ -1447,8 +1447,12 @@ static int wake_srv_chk(struct conn_stream *cs) ret = tcpcheck_main(check); cs = check->cs; conn = cs->conn; - } else if (!(check->wait_list.events & SUB_RETRY_SEND)) - __event_srv_chk_w(cs); + } else { + if (!(check->wait_list.events & SUB_RETRY_SEND)) + __event_srv_chk_w(cs); + if (!(check->wait_list.events & SUB_RETRY_RECV)) + __event_srv_chk_r(cs); + } if (unlikely(conn->flags & CO_FL_ERROR || cs->flags & CS_FL_ERROR)) { /* We may get error reports bypassing the I/O handlers, typically @@ -2260,7 +2264,9 @@ static struct task *process_chk_conn(struct task *t, void *context, unsigned sho * sending since otherwise we won't be woken up. */ __event_srv_chk_w(cs); - __event_srv_chk_r(cs); + if (!(conn->flags & CO_FL_WAIT_L4_CONN) || + !(check->wait_list.events & SUB_RETRY_SEND)) + __event_srv_chk_r(cs); } task_set_affinity(t, tid_bit); -- 2.39.5