Skip to content

Commit b030aaf

Browse files
therealalephclaude
andcommitted
v1.6.4: fix Full-mode L7 muxer not batching ops (#231)
The batch-build loop blocked on a 30 ms timeout for the first message, then drained whatever else was in the channel via try_recv() and fired the batch. Under any non-bursty workload, the channel queue was always empty by the time the first op woke us up — so every "batch" had exactly one op, defeating the entire batching premise. Reporter (w0l4i) saw `batch: 1 ops → ..., rtt=6.3 s` repeating in logs even under high concurrency. Fix: after the first op lands, hold the buffer open for an 8 ms coalescing window. Concurrent ops (parallel fetches, HTTP/2 stream openings, etc.) now accumulate into the same batch. 8 ms is rounding error against the 2–7 s Apps Script RTT we're amortizing, and restores the multi-op-per-batch behavior the rest of the code already supports (MAX_BATCH_OPS=50, MAX_BATCH_PAYLOAD_BYTES=4 MiB). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 2c8fcc7 commit b030aaf

5 files changed

Lines changed: 40 additions & 10 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mhrv-rs"
3-
version = "1.6.3"
3+
version = "1.6.4"
44
edition = "2021"
55
description = "Rust port of MasterHttpRelayVPN -- DPI bypass via Google Apps Script relay with domain fronting"
66
license = "MIT"

android/app/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ android {
1414
applicationId = "com.therealaleph.mhrv"
1515
minSdk = 24 // Android 7.0 — covers 99%+ of live devices.
1616
targetSdk = 34
17-
versionCode = 142
18-
versionName = "1.6.3"
17+
versionCode = 143
18+
versionName = "1.6.4"
1919

2020
// Ship all four mainstream Android ABIs:
2121
// - arm64-v8a — 95%+ of real-world Android phones since 2019

docs/changelog/v1.6.4.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<!-- see docs/changelog/v1.1.0.md for the file format: Persian, then `---`, then English. -->
2+
• رفع باگ "L7 multiplexer در Full mode batch نمی‌کنه" ([#231](https://github.com/therealaleph/MasterHttpRelayVPN-RUST/issues/231)): در حالت Full، انتظار می‌رفت که چند op به یک batch HTTP request به Apps Script ترکیب بشن (`batch: 5 ops` یا `batch: 10 ops`)، ولی log نشون می‌داد همیشه `batch: 1 ops` — یعنی هر op جدا یه round-trip Apps Script می‌گرفت (که هر کدوم 2 تا 7 ثانیه طول می‌کشن). علت: loop دریافت پیام بلافاصله بعد از اولین message با `try_recv()` (non-blocking) صف رو drain می‌کرد، بدون pause برای جمع‌آوری بقیه ops. **Fix:** بعد از اولین op، یه پنجرهٔ ۸ میلی‌ثانیه‌ای باز می‌مونه تا opهای بعدی (مثل parallel fetches، HTTP/2 streams) همون batch رو پر کنن. ۸ms در مقابل ~۲ تا ۷ ثانیه RTT Apps Script اصلاً ناچیزه ولی efficiency batching رو برمی‌گردونه. ریپورت شده توسط w0l4i با log واضح
3+
---
4+
• Fix "L7 multiplexer not batching in Full mode" bug ([#231](https://github.com/therealaleph/MasterHttpRelayVPN-RUST/issues/231)): in `full` mode, multiple ops should coalesce into a single batched HTTP request to Apps Script (`batch: 5 ops` or `batch: 10 ops`), but logs showed `batch: 1 ops` consistently — each op got its own Apps Script round-trip (2-7 s each). Cause: the receive loop drained the channel via `try_recv()` (non-blocking) immediately after the first message arrived, with no window to let concurrent ops accumulate. **Fix:** after the first op lands, hold the buffer open for an 8 ms coalescing window so concurrent ops (parallel fetches, HTTP/2 stream openings, etc.) land in the same batch. 8 ms is rounding error against the ~2-7 s Apps Script RTT but restores the entire batching premise. Reported by w0l4i with a clean log snippet

src/tunnel_client.rs

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ const REPLY_TIMEOUT: Duration = Duration::from_secs(35);
5555
/// connect saves one Apps Script round-trip per new flow.
5656
const CLIENT_FIRST_DATA_WAIT: Duration = Duration::from_millis(50);
5757

58+
/// How long the muxer holds open the batch buffer after the first op
59+
/// arrives, waiting for more ops to coalesce. Issue #231 — the previous
60+
/// implementation drained `try_recv()` *immediately* after the first
61+
/// message landed, so under any non-bursty workload every batch held
62+
/// exactly one op (defeating the entire batching premise). 8 ms is small
63+
/// vs the ~2-7 s Apps Script round-trip the batch is amortizing, but
64+
/// long enough that concurrent HTTP/2 stream openings, parallel fetches,
65+
/// or any other burst lands in the same batch.
66+
const BATCH_COALESCE_WINDOW: Duration = Duration::from_millis(8);
67+
5868
/// Structured error code the tunnel-node returns when it doesn't know the
5969
/// op (version mismatch). Must match `tunnel-node/src/main.rs`.
6070
const CODE_UNSUPPORTED_OP: &str = "UNSUPPORTED_OP";
@@ -319,13 +329,29 @@ async fn mux_loop(mut rx: mpsc::Receiver<MuxMsg>, fronter: Arc<DomainFronter>) {
319329

320330
loop {
321331
let mut msgs = Vec::new();
322-
match tokio::time::timeout(Duration::from_millis(30), rx.recv()).await {
323-
Ok(Some(msg)) => msgs.push(msg),
324-
Ok(None) => break,
325-
Err(_) => continue,
332+
// Block on the first message — no point waking up to find an empty
333+
// queue. Once the first op lands, we hold open BATCH_COALESCE_WINDOW
334+
// so concurrent ops (parallel fetches, HTTP/2 stream openings, etc.)
335+
// land in the same batch instead of getting a fresh round-trip each.
336+
match rx.recv().await {
337+
Some(msg) => msgs.push(msg),
338+
None => break,
326339
}
327-
while let Ok(msg) = rx.try_recv() {
328-
msgs.push(msg);
340+
let deadline = tokio::time::Instant::now() + BATCH_COALESCE_WINDOW;
341+
loop {
342+
// Drain anything that's already queued without waiting.
343+
while let Ok(msg) = rx.try_recv() {
344+
msgs.push(msg);
345+
}
346+
let now = tokio::time::Instant::now();
347+
if now >= deadline {
348+
break;
349+
}
350+
match tokio::time::timeout(deadline - now, rx.recv()).await {
351+
Ok(Some(msg)) => msgs.push(msg),
352+
Ok(None) => return,
353+
Err(_) => break,
354+
}
329355
}
330356

331357
// Split: plain connects go parallel, data-bearing ops get batched.

0 commit comments

Comments
 (0)