Skip to content

investigate accept queue management #497

Closed

Description

@Geal

see Bandaid's approach in https://blogs.dropbox.com/tech/2018/03/meet-bandaid-the-dropbox-service-proxy/

TL;DR: instead of of accepting new connections when we have room for them, accept them right away but put them into a queue, and remove them from the queue if they're too old (since the client might have already closed the connection).
This is important because when a connection is in the accept queue, the TCP handshake has already been done by the kernel, and the client is already waiting. So the response time of the server does not start when the connection is accepted, but some time before.

Activity

  1. Geal commented on Aug 24, 2018

    @Geal
    MemberAuthor

    here's how accepting connections is done right now:

    • we register all the listen queues in the same event loop
    • whenever one of them gets a readable event, we call Server::accept() in lib/src/network/proxy.rs with its token, in a loop, until it stops accepting
    • that accept() method looks up the token in the clients slab, and select the appropriate proxy implementation (HTTP, HTTPS or TCP), and call their own accept() method, passing a reference to the event loop, and a new token to register the new socket in the clients slab
    • the proxy implementation will then look up the listener associated with the token, call its accept method, and if it got a socket, create the client session

    To move to a userspace accept queue like in bandaid, here is what we should do:

    • small optimization: the Server::accept() method would look up the proxy implementation associated with the token, but only call the proxy's accept() once (instead of look up in a loop)
    • a proxy implementation's accept() method would accept connections in a loop, and return a list of sockets
    • the event loop would then add them to a VecDeque<(TcpStream, ListenToken, SteadyTime)>, to associate the socket with its listener and the time of creation
    • the event loop, after handling all of the current events, would go through that queue (in LIFO), and for each element, if the socket is not too old (configurable timeout), look up the proxy impl from its listen token, call its create_client method, passing a reference to the event loop, the listen token and a new token for the session
    • the create_client method will create a new client session and associate it to the listener

    possible optimization: go through the entire queue, apply one filter to remove the connections that are too old, and the one we can accept, sort them by listen token, to call the proxy impl's create_client method in a loop instead of looking it up for each socket.

  2. Geal commented on Aug 31, 2018

    @Geal
    MemberAuthor

    implemented in 0dc66ca and 53e394d.
    New metrics are available to track the accept queue:

    • accept_queue.count (gauge): number of sockets currently in the accept queue
    • accept_queue.timeout (counter): incremented every time we drop a connection because it stayed more than 60 seconds in the accept queue
    • accept_queue.wait_time (time, milliseconds): time spent in the accept queue for each socket
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions