Skip to content

Optimize Guest#28

Open
lacraig2 wants to merge 7 commits intomainfrom
opt_guest
Open

Optimize Guest#28
lacraig2 wants to merge 7 commits intomainfrom
opt_guest

Conversation

@lacraig2
Copy link
Contributor

@lacraig2 lacraig2 commented Nov 3, 2025

This PR does the following:

  • switches the guest to use a single-threaded tokio engine
  • switches the guest to use copy_bidirectional
  • adds a sleep in a hot path in the host
  • pins our csv to an older version because of rust version restrictions (relevant for MIPS)

@lacraig2 lacraig2 requested a review from Copilot November 4, 2025 16:51
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the UDP proxying implementation from per-client vsock streams to a multiplexed architecture where a single vsock stream handles all UDP clients for a given service. The changes also optimize the guest runtime to use a single-threaded executor instead of multi-threaded.

Key changes:

  • Introduced UdpMuxPacket structure to multiplex UDP packets over a single vsock stream with client address information
  • Replaced HostRequest::Forward with separate ForwardTcp and ForwardUdpMux variants to distinguish between TCP and UDP multiplexed forwarding
  • Changed guest runtime from multi-threaded to single-threaded for better resource efficiency

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/main.rs Added UdpMuxPacket struct, split HostRequest::Forward into ForwardTcp and ForwardUdpMux, changed guest runtime to single-threaded, added EOF check in read_event
src/host.rs Refactored UDP proxy from per-client to multiplexed architecture, updated TCP forwarding to use new ForwardTcp variant, added sleep on empty line reads
src/guest.rs Implemented multiplexed UDP proxy with per-client task spawning, replaced manual TCP forwarding with tokio::io::copy, updated to handle new request variants
Cargo.toml Pinned dependency versions and added serde_bytes for efficient binary serialization

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

let client_addr = packet.client_addr;

if let Some(tx) = clients.get(&client_addr) {
if tx.send(packet.data).await.is_err() {
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

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

When a send fails to an existing client, the client is removed but the packet data is lost. This could lead to dropped packets. Consider either logging the dropped packet or attempting to recreate the client handler to process the packet.

Suggested change
if tx.send(packet.data).await.is_err() {
if tx.send(packet.data).await.is_err() {
error!(
client = %client_addr,
size = packet.data.len(),
"Dropped packet: failed to send to client, removing client handler"
);

Copilot uses AI. Check for mistakes.
tokio-vsock = "0.6.0"
tracing = "0"
csv = "1.1"
csv = "=1.3.0"
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

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

Using an exact version requirement (=1.3.0) prevents patch updates that could include bug fixes. Consider using a more flexible version specifier like '1.3' or '~1.3.0' unless there's a specific reason to pin to this exact version.

Suggested change
csv = "=1.3.0"
csv = "1.3"

Copilot uses AI. Check for mistakes.
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.

2 participants