You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
Activity
Geal commentedon Aug 24, 2018
here's how accepting connections is done right now:
readableevent, we callServer::accept()inlib/src/network/proxy.rswith its token, in a loop, until it stops acceptingaccept()method looks up the token in the clients slab, and select the appropriate proxy implementation (HTTP, HTTPS or TCP), and call their ownaccept()method, passing a reference to the event loop, and a new token to register the new socket in the clients slabTo move to a userspace accept queue like in bandaid, here is what we should do:
Server::accept()method would look up the proxy implementation associated with the token, but only call the proxy'saccept()once (instead of look up in a loop)accept()method would accept connections in a loop, and return a list of socketsVecDeque<(TcpStream, ListenToken, SteadyTime)>, to associate the socket with its listener and the time of creationcreate_clientmethod, passing a reference to the event loop, the listen token and a new token for the sessioncreate_clientmethod will create a new client session and associate it to the listenerpossible 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_clientmethod in a loop instead of looking it up for each socket.Geal commentedon Aug 31, 2018
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 queueaccept_queue.timeout(counter): incremented every time we drop a connection because it stayed more than 60 seconds in the accept queueaccept_queue.wait_time(time, milliseconds): time spent in the accept queue for each socket