MINOR: raw_sock: make sure to disable polling once everything is sent
authorWilly Tarreau <w@1wt.eu>
Wed, 8 Jan 2020 08:54:02 +0000 (09:54 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 8 Jan 2020 08:59:40 +0000 (09:59 +0100)
commit08fa16e397ffb1c6511b98ade2a3bfff9435e521
treef783e89cbf5d9bd1e331eba5ad4c30cb9c0b64d7
parent0eae6323bf8a3bb8e6a399f4f09971e388a4ced5
MINOR: raw_sock: make sure to disable polling once everything is sent

Analysing traces revealed a rare but surprizing pattern :

    connect()  = -1 EAGAIN
    send()     = success
    epoll_ctl(ADD, EPOLLOUT)
    epoll_wait()
    recvfrom() = success
    close()

What happens is that the failed connect() creates an FD update for pollout,
but the successful synchronous send() doesn't disable it because polling was
only disabled in the FD handler. But a successful synchronous connect()
cancellation is a good opportunity to disable polling before it's effectively
enabled in the next loop, so better disable it when reaching the end. The
cost is very low if it was already disabled anyway (one atomic op).

This only affects local connections but with this the typical number of
epoll_ctl() calls per connection dropped from ~4.2 to ~3.8 for plain TCP
and 10k transfers.
src/raw_sock.c