Skip to content

Refactor the event loop - #340

Merged
Geal merged 34 commits into
masterfrom
ready-refactor
Feb 21, 2018
Merged

Geal merged 34 commits into
masterfrom
ready-refactor

Conversation

@Geal

@Geal Geal commented Feb 2, 2018 •

Copy link
Copy Markdown
Member

Right now, a client connection is represented by a structure that must implement the ProxyClient trait. That trait exposes methods to set up the front and back connections, along with readable writable, back_readable and back_writable methods, that the Session object will call in the event loop in its ready method.
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 ProxyClient trait 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):

  • move the event loop from Session::ready() in each of the ProxyClient implementations. This has an interesting side effect: the event loop could execute self.clients[client_token] 15 times in a loop, and the element could be remove from the clients slab at any time in the loop. Now, we look up self.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 the Session::interpret_client_order() method in the ProxyConfiguration trait not really possible, since we must manipulate the list of clients, and that is not in the ProxyConfiguration
  • remove all the front/back methods from ProxyClient that are not called anymore from Session::ready

@CLAassistant

CLAassistant commented Feb 2, 2018 •

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@Geal
Geal requested review from BlackYoup and NotBad4U February 2, 2018 16:29

@BlackYoup BlackYoup left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nitpicks, it seems to be mostly copy paste, so LGTM

Comment thread lib/src/network/tcp.rs Outdated
}

fn ready(&mut self) -> ClientResult {
let mut counter = 0;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation's weird

Comment thread lib/src/network/https_rustls/client.rs Outdated
}

fn ready(&mut self) -> ClientResult {
let mut counter = 0;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation's weird

Comment thread lib/src/network/https_openssl.rs Outdated
}

fn ready(&mut self) -> ClientResult {
let mut counter = 0;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation's weird

@Geal

Geal commented Feb 9, 2018

Copy link
Copy Markdown
Member Author

so, the refactoring is mostly done. It still needs a lot of code cleaning, but everything will be much nicer to manipulate now.
I'm not completely happy about parts of the design (like those methods), but overall it is cleaner that what was available previously.

Now, all the clients are stored in the same Slab, and there is no more weird Token arithmetic to know which proxy handles which event.

Geal added 22 commits February 16, 2018 15:33
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)
Geal added 10 commits February 16, 2018 16:38
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.
@Geal
Geal merged commit 5d50b5e into master Feb 21, 2018
@Geal
Geal deleted the ready-refactor branch June 6, 2019 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants