Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite net::client::redundant #462

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft

Rewrite net::client::redundant #462

wants to merge 7 commits into from

Conversation

bal-e
Copy link
Contributor

@bal-e bal-e commented Dec 4, 2024

This is a low-priority PR for simplifying the Redundant client transport. I've managed to replace a large and difficult state machine with a much simpler control flow, making good use of the futures_util crate. The module has become significantly smaller and easier to understand.

bal-e added 5 commits December 4, 2024 16:32
The new implementation is significantly simpler and shorter.  There are
two important changes to discuss:

- The 'Transport' type and worker task have been replaced by a simple
  concurrent data structure within 'Connection'.  This eliminates an
  unnecessary synchronization point for performing requests: now, many
  requests can be launched from multiple threads simultaneously.

- The 'QueryState' based state machine has been replaced with a simple
  async function definition, that iterates through transports and then
  falls back to waiting on all running connections.  It is far easier
  to understand the control flow here.

  - Instead of 'tokio::select!{}' in a loop, we use 'buffer_unordered'
    to dynamically collect ongoing requests (which we produce following
    timeouts).

  - Instead of tracking IDs for transports, we wrap them in 'Arc's and
    then give out references to them.  Transport statistics can then be
    updated directly, without external communication.

  - Instead of 'QueryState::Report()', we use a drop guard in the
    underlying request futures.  This directly writes to a statistics
    structure that is shared with all threads.

The end result is a smaller, more readable codebase.  'Connection::new'
no longer returns a separate 'Transport' type.  'Connection::add' has
become a synchronous, infallible function.  Multiple requests can be
performed in parallel, without having to request data from a task.
This removes a layer of vtables that may not be necessary in some
applications.  However, it complicates the typing -- we'll see whether
it's worthwhile.
@bal-e bal-e self-assigned this Dec 4, 2024
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.

1 participant