Skip to content

Conversation

@amphi
Copy link

@amphi amphi commented Dec 10, 2025

This PR makes the REST API multi threaded, i.e. if a REST API call blocks, you can still send requests that the VMM will respond to (if possible).

Copy link
Member

@phip1611 phip1611 left a comment

Choose a reason for hiding this comment

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

Thanks for working on this! I think this can be massively simplified with

  • a single sender for requests (does not even has to be a sync sender but could be)
  • a single receiver for requests that is shared by all worker threads

It would remove a lot of complexity, remove the manual round robin implementation, etc.


/// Returns a channel to a worker thread that is ready for more work, if
/// any workers are ready.
fn next_worker(&mut self) -> std::option::Option<&std::sync::mpsc::SyncSender<ServerRequest>> {
Copy link
Member

Choose a reason for hiding this comment

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

to me, this looks overly complicated. I actually thought about a solution where all worker threads blockingly receiver.recv() on a channel with Http Requests.

Then we also don't need a round robin algorithm. The thread that is ready picks up the request from the channel. That's a typical pattern for thread pools in Rust.

Is there a reason you decided against this?

Copy link
Author

Choose a reason for hiding this comment

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

Because I didn't know that you can use an MPSC channel with multiple consumers. But your idea is very good, it made everything easier!

threads_ready: Vec<bool>,
// An MPSC channel for every worker. We use this to send server requests
// to the workers.
request_txs: Vec<std::sync::mpsc::SyncSender<ServerRequest>>,
Copy link
Member

Choose a reason for hiding this comment

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

why is this a vector of senders? I thought about one single Sender (does not even has to be syncsender) and a shared receiver by all worker threads. This would remove most of the complexity you have here

Copy link
Author

Choose a reason for hiding this comment

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

Did that, see comment above.

@amphi amphi force-pushed the http-multi-threaded branch from 01458e7 to 8ffaea8 Compare December 10, 2025 15:38
@amphi amphi requested a review from phip1611 December 10, 2025 15:40
Copy link
Member

@phip1611 phip1611 left a comment

Choose a reason for hiding this comment

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

Nice, definitely better! I think we can also entirely get rid of the epoll stuff and just use standard Rust channels for everything, further simplifying things.

response_rx: std::sync::mpsc::Receiver<ServerResponse>,
// Workers signal this eventfd when they have a response for the HTTP
// server thread.
response_event: EventFd,
Copy link
Member

Choose a reason for hiding this comment

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

theoretically we could also get rid of this and use a channel from the workers to the server, right? Then all thredas would have the same sender (without the need for arc<mutex> as this works out of the box) and the main thread the receiver.

Thoughts?

Copy link
Author

Choose a reason for hiding this comment

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

We have a channel from the worker threads to the main thread, but I don't understand why that means that we can get rid of this eventfd. The main thread has to monitor two things:

  • Requests from the API, that it has to distribute to the workers
  • Responses from the workers, that it has to forward to the http_server.

The only usable mechanism here (that I know of) is the epoll mechanism, and we need this eventfd for that.

Copy link
Member

Choose a reason for hiding this comment

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

from offline discussion. it is okay to keep as we need eventfd handling with the underlying http server anyway

@amphi amphi force-pushed the http-multi-threaded branch from 8ffaea8 to b402674 Compare December 11, 2025 09:34
@amphi amphi requested a review from phip1611 December 11, 2025 09:55
Copy link
Member

@phip1611 phip1611 left a comment

Choose a reason for hiding this comment

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

LGTM

@phip1611 phip1611 requested a review from scholzp December 12, 2025 10:38
@phip1611 phip1611 changed the title Make REST API multi threaded Make HTTP Server multi threaded Dec 15, 2025
Copy link

@olivereanderson olivereanderson left a comment

Choose a reason for hiding this comment

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

LGTM

I think this is the simplest way to make the existing HTTP server multi-threaded :)

On-behalf-of: SAP sebastian.eydam@sap.com
Signed-off-by: Sebastian Eydam <sebastian.eydam@cyberus-technology.de>
@phip1611 phip1611 force-pushed the http-multi-threaded branch from b402674 to 14f71be Compare December 15, 2025 14:16
@phip1611 phip1611 enabled auto-merge (rebase) December 15, 2025 14:16
@phip1611 phip1611 merged commit fa7e514 into cyberus-technology:gardenlinux Dec 15, 2025
14 checks passed
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