Repository navigation
Refactor the event loop - #340
Conversation
|
|
BlackYoup
left a comment
There was a problem hiding this comment.
Some nitpicks, it seems to be mostly copy paste, so LGTM
| } | ||
|
|
||
| fn ready(&mut self) -> ClientResult { | ||
| let mut counter = 0; |
| } | ||
|
|
||
| fn ready(&mut self) -> ClientResult { | ||
| let mut counter = 0; |
| } | ||
|
|
||
| fn ready(&mut self) -> ClientResult { | ||
| let mut counter = 0; |
|
so, the refactoring is mostly done. It still needs a lot of code cleaning, but everything will be much nicer to manipulate now. Now, all the clients are stored in the same |
this will make the Session implementation a bit smaller, it will allow a much smaller ProxyClient trait, and from there, implementing protocols like http/2 that can have multiple backend connections, will be much easier
this will allow clients that can have multiple backend connections. It also simplifies the design a bit, since there is now no specific range for backend tokens
we cannot be sure that we used the front token to get the client and then call close() on it, so we return all the tokens, so all the refcounted containers for the client are removed
CloseClient will close front and back in all cases
This allows a much cleaner design, since there is no separation of client slabs per proxy: they are all stored in the same one (this causes some typing issues that could be resolved later). This means no more token arithmetic, everything handled at the same level, and possibly a slight perf boost, since we might have less indirection. This has been quickly tested, we will need to wait a bit before we're sure it does not break everything. The code for the OpenSSL based HTTPS proxy has not been fully ported during this refactoring, thereare are a few changes to the traits to perform. There is still some inconsistencies with the TCP proxy (adding a new listener does not work yet, as this message requires a special case)
before, we only stopped accepting new connections when we reached the limit, so new connections could stay in the listen socket's queue until there's enough room for a new client. Unfortunately, that means a new connection could wait a long time and timeout (and occupy valuable ressources in the meantime). Since reaching the limit is supposed to be a rare case, and we want to keep acceptable performance even in degenrate cases, this commit lets us close all new pending connections when're under already heavy load, and start accepting again when we have enough room.
Right now, a client connection is represented by a structure that must implement the
ProxyClienttrait. That trait exposes methods to set up the front and back connections, along withreadablewritable,back_readableandback_writablemethods, that theSessionobject will call in the event loop in itsreadymethod.To implement HTTP/2, we need a way to have multiple backend connections for one frontend connection, so the current design will not work. Also, the
ProxyClienttrait exposes a lot of methods that might not be useful to the upper layer (they are there mainly because of the current design).So, here's the plan (in progress, I'll update this PR as I continue working on this):
Session::ready()in each of theProxyClientimplementations. This has an interesting side effect: the event loop could executeself.clients[client_token]15 times in a loop, and the element could be remove from theclientsslab at any time in the loop. Now, we look upself.clients[client_token]one time, then call a method on it, which might improve performance (I have not measured the difference yet)if possible, move thenot really possible, since we must manipulate the list of clients, and that is not in theSession::interpret_client_order()method in theProxyConfigurationtraitProxyConfigurationProxyClientthat are not called anymore fromSession::ready