fix: improve SDK UDP throughput and transport selection

Yield during UDP receive bursts to let session consumers drain bounded queues. Prioritize measured RTT over protocol preference and enlarge user-space subnet TCP buffers with validated limits.

Add packet-level throughput diagnostics, transport selection coverage, and investigation records. SDK regression suite: 21 tests passed; local delay and throughput experiments documented.
This commit is contained in:
shen
2026-10-15 23:53:10 -07:00
parent c1d0739b95
commit b656c1896a
21 changed files with 1954 additions and 33 deletions
+3 -1
View File
@@ -7,12 +7,13 @@ Imported using git archive. Retained LGPL-3.0 LICENSE and upstream crate sources
This is a local source customization, not a published GitHub fork. Root workspace members were limited to easytier, easytier-core and easytier-proto for the SDK build. MeshPort root uses path dependencies and its own Cargo.lock.
Local modifications:
- easytier-core/src/socket/udp/layer.rs: yield after batches of 32 received datagrams so session-ring consumers can run before the fixed 128-slot queues overflow during bursts. Keeps queue capacities and enqueue/drop policies unchanged. Local encrypted SDK diagnostics count queue-full events and TCP sequence repeats; live WAN validation remains pending.
- easytier/src/common/dns.rs: resolve numeric bootstrap addresses without DNS, including when a platform socket protector is installed.
- easytier/src/common/network.rs: macOS hardware enumeration uses blocking subprocess waits; physical connection candidates exclude route-probe addresses and nonphysical IPv6 interfaces so another VPN's TUN is not reintroduced. Hardware device names match exactly.
- easytier-core/src/peers/meshport_optimization.rs: direct preference, improvement thresholds, hold/cooldown and candidate first-hop filter.
- easytier-core/src/peers/mod.rs: exposes policy module.
- easytier-core/src/peers/conn/peer_map.rs: local policy and bounded decision caches.
- easytier-core/src/peers/conn/peer.rs: optional UDP preference, skip closed connections, resolve default selection for status/fallback.
- easytier-core/src/peers/conn/peer.rs and selection.rs: measured RTT precedes protocol preference; optional UDP preference breaks equal-RTT ties, unverified punched connections cannot displace verified links. Skip closed connections, resolve default selection for status/fallback.
- easytier-core/src/peers/peer_manager.rs: policy configuration and effective next-hop inspection.
- easytier/src/common/ifcfg/mod.rs: macOS interface commands use blocking-pool subprocess waits rather than Tokio SIGCHLD-driven waits, for embedded runtime compatibility.
- easytier-core/src/instance/packet_plane.rs: optional host subnet filter for route projection.
@@ -20,6 +21,7 @@ Local modifications:
- easytier/src/instance/virtual_nic.rs: recompute filtered route deltas on events and periodic refresh, retry failed route additions.
- easytier/Cargo.toml and easytier/src/instance/config.rs: expose the existing core packet proxy as an independent native host capability for subnet-gateway tests, without requiring KCP/QUIC. SDK production builds do not enable it.
- easytier-core/src/gateway/dataplane/stack.rs: data-plane TCP socket buffers raised from 128 KiB to 1 MiB receive / 512 KiB transmit, lifting the single-stream window ceiling (window / RTT). Wire format unchanged; window scaling is negotiated from buffer size.
- easytier-core/src/gateway/smoltcp/stack.rs: user-space subnet TCP buffers raised from 16 KiB each to 1 MiB receive / 128 KiB transmit. Keeps transmit buffering below the SDK's 512 KiB after local short-download regressions with that value. Allocates about 1.125 MiB per socket, including pending handshakes. Applies on the subnet gateway running this code, not on unmodified remote EasyTier gateways.
- Cargo.toml: reduced workspace member list.
No packet/protobuf wire-format modification. Do not assume mixed-version interoperability from local tests alone. Before upstream updates, compare these files against the pinned revision and rerun MeshPort real overlay and transport fallback tests. See ../../docs/optimization.md for policy limits.
+6 -2
View File
@@ -56,8 +56,12 @@ impl SmolTcpStack {
format!("{local_ip}/24").parse().unwrap(),
vec![format!("{local_ip}").parse().unwrap()],
Some(BufferSize {
tcp_rx_size: 1024 * 16,
tcp_tx_size: 1024 * 16,
// Raise the receive window as in the SDK data plane, but
// keep subnet transmit buffering smaller: 512 KiB caused
// short-download regressions in local diagnostics. Allocated
// per socket (including handshakes): ~1.125 MiB for rx + tx.
tcp_rx_size: 1024 * 1024,
tcp_tx_size: 1024 * 128,
..Default::default()
}),
),
+2
View File
@@ -7,3 +7,5 @@ pub(crate) mod peer_conn_liveness;
pub(crate) mod peer_conn_ping;
pub(crate) mod peer_map;
pub(crate) mod peer_session;
mod selection;
+5 -26
View File
@@ -26,9 +26,7 @@ use tokio_util::task::AbortOnDropHandle;
type ArcPeerConn = Arc<PeerConn>;
type ConnMap = Arc<DashMap<PeerConnId, ArcPeerConn>>;
fn conn_latency_sort_key(latency_us: u64, is_hole_punched: bool) -> (bool, u64) {
(is_hole_punched && latency_us == 0, latency_us)
}
use super::selection::conn_selection_key;
pub struct Peer {
pub peer_node_id: PeerId,
@@ -238,11 +236,12 @@ impl Peer {
.get_conn_info()
.tunnel
.is_some_and(|t| t.tunnel_type == "udp");
let base = conn_latency_sort_key(
conn_selection_key(
conn.value().get_stats().latency_us,
conn.value().is_hole_punched(),
);
(base.0, self.prefer_udp.load() && !is_udp, base.1)
is_udp,
self.prefer_udp.load(),
)
})
.map(|conn| conn.value().clone());
@@ -350,23 +349,3 @@ impl Drop for Peer {
tracing::info!("peer {} drop", self.peer_node_id);
}
}
#[cfg(test)]
mod tests {
use super::conn_latency_sort_key;
#[test]
fn measured_relay_precedes_unverified_hole_punch_path() {
assert!(conn_latency_sort_key(20_000, false) < conn_latency_sort_key(0, true));
}
#[test]
fn unmeasured_regular_connection_keeps_existing_priority() {
assert!(conn_latency_sort_key(0, false) < conn_latency_sort_key(20_000, false));
}
#[test]
fn verified_lower_latency_path_can_be_preferred() {
assert!(conn_latency_sort_key(5_000, true) < conn_latency_sort_key(20_000, false));
}
}
@@ -0,0 +1,68 @@
//! Transport selection ordering, independent of connection ownership.
fn conn_latency_sort_key(latency_us: u64, is_hole_punched: bool) -> (bool, u64) {
(is_hole_punched && latency_us == 0, latency_us)
}
pub(super) fn conn_selection_key(
latency_us: u64,
is_hole_punched: bool,
is_udp: bool,
prefer_udp: bool,
) -> (bool, u64, bool) {
let (unverified, latency) = conn_latency_sort_key(latency_us, is_hole_punched);
// A protocol preference must not override a measured RTT advantage.
// Keep unverified hole-punched links behind measured links, and use UDP
// only to break an RTT tie when the preference is enabled.
(unverified, latency, prefer_udp && !is_udp)
}
#[cfg(test)]
mod tests {
use super::{conn_latency_sort_key, conn_selection_key};
#[test]
fn udp_preference_does_not_replace_a_faster_measured_connection() {
let tcp = conn_selection_key(7_000, false, false, true);
let udp = conn_selection_key(58_000, true, true, true);
assert!(tcp < udp);
assert!(
conn_selection_key(7_000, true, true, true)
< conn_selection_key(58_000, false, false, true)
);
}
#[test]
fn udp_preference_breaks_equal_rtt_ties_only() {
assert!(
conn_selection_key(7_000, true, true, true)
< conn_selection_key(7_000, false, false, true)
);
assert_eq!(
conn_selection_key(7_000, true, true, false),
conn_selection_key(7_000, false, false, false)
);
}
#[test]
fn udp_preference_does_not_promote_an_unverified_punched_link() {
assert!(
conn_selection_key(7_000, false, false, true) < conn_selection_key(0, true, true, true)
);
}
#[test]
fn measured_relay_precedes_unverified_hole_punch_path() {
assert!(conn_latency_sort_key(20_000, false) < conn_latency_sort_key(0, true));
}
#[test]
fn unmeasured_regular_connection_keeps_existing_priority() {
assert!(conn_latency_sort_key(0, false) < conn_latency_sort_key(20_000, false));
}
#[test]
fn verified_lower_latency_path_can_be_preferred() {
assert!(conn_latency_sort_key(5_000, true) < conn_latency_sort_key(20_000, false));
}
}
+9
View File
@@ -446,6 +446,7 @@ pub(super) async fn udp_session_layer_recv_task<S, R>(
R: UdpSessionStunResponder<S>,
{
let control_permits = Arc::new(Semaphore::new(UDP_SESSION_QUEUE_CAPACITY));
let mut recv_batch = 0usize;
loop {
let datagram = match socket.recv_session_datagram().await {
Ok(datagram) => datagram,
@@ -461,6 +462,14 @@ pub(super) async fn udp_session_layer_recv_task<S, R>(
let payload = datagram.payload;
let remote_addr = datagram.remote_addr;
let recv_meta = datagram.meta;
// A ready UDP socket can monopolize this task until Tokio's IO budget
// expires, filling session rings before their consumers get scheduled.
// Yield in smaller batches without blocking the shared socket on a peer.
recv_batch += 1;
if recv_batch >= 32 {
recv_batch = 0;
tokio::task::yield_now().await;
}
if payload.len() > MAX_UDP_SESSION_DATAGRAM_SIZE {
tracing::debug!(
datagram_len = payload.len(),