Commit eb1d00c
committed
perf(tunnel): dynamic coalescing, O(n) upload buffer, network_preset config
Steps 3 + 4 of the perf/relay-speed series.
--- Step 3: Dynamic coalescing (tunnel_client.rs + config.rs + proxy_server.rs) ---
Replace static DEFAULT_COALESCE_STEP/MAX constants with Arc<AtomicU64> values
stored in TunnelMux. A new RttTracker (ring buffer of last 8 batch RTTs)
measures median round-trip time and auto-adjusts the coalesce window:
Slow preset (median > 1200ms): step=150ms max=600ms
Fast preset (median < 700ms): step= 50ms max=300ms
Hysteresis: 3 consecutive sub-threshold readings required to leave Slow,
preventing flapping on bursty congestion. mux_loop reads the atomics at each
new window boundary so preset changes take effect without restart.
Config: network_preset = "auto" (default) | "fast" | "slow"
- auto starts at Fast and adapts via RttTracker
- fast/slow lock the preset and skip RTT measurement
Explicit coalesce_step_ms / coalesce_max_ms override still honoured when set;
presence of either disables auto-adaptation.
Note: TunnelMux is only started in mode=full. Mode=apps_script relays each
connection directly through DomainFronter and does not go through this path.
New unit tests: rtt_tracker_preset_selection_slow,
rtt_tracker_preset_selection_fast, rtt_tracker_hysteresis_prevents_premature_flip.
Fixed copy_bidirectional test in proxy_server.rs: a_client was moved into
write_task then borrowed for reading — split into separate read/write halves
before spawning so both directions can be independently asserted.
--- Step 4: O(n) amortised buffered upload merge (tunnel_client.rs) ---
Change buffered_upload from Option<Bytes> to Option<BytesMut>. The old merge
path allocated a fresh buffer and copied all accumulated data on every new
upload chunk under pipeline congestion — O(n^2) total copies for n chunks.
BytesMut extends in-place (amortised O(n)); freeze() at send time is a
zero-copy Arc pointer bump.1 parent 1615576 commit eb1d00c
3 files changed
Lines changed: 362 additions & 59 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
115 | 122 | | |
116 | 123 | | |
117 | 124 | | |
| |||
785 | 792 | | |
786 | 793 | | |
787 | 794 | | |
| 795 | + | |
| 796 | + | |
788 | 797 | | |
789 | 798 | | |
790 | 799 | | |
| |||
935 | 944 | | |
936 | 945 | | |
937 | 946 | | |
| 947 | + | |
938 | 948 | | |
939 | 949 | | |
940 | 950 | | |
| |||
977 | 987 | | |
978 | 988 | | |
979 | 989 | | |
| 990 | + | |
980 | 991 | | |
981 | 992 | | |
982 | 993 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
220 | 220 | | |
221 | 221 | | |
222 | 222 | | |
| 223 | + | |
223 | 224 | | |
224 | 225 | | |
225 | 226 | | |
| |||
527 | 528 | | |
528 | 529 | | |
529 | 530 | | |
| 531 | + | |
530 | 532 | | |
531 | 533 | | |
532 | 534 | | |
| |||
548 | 550 | | |
549 | 551 | | |
550 | 552 | | |
551 | | - | |
| 553 | + | |
552 | 554 | | |
553 | 555 | | |
554 | 556 | | |
| |||
3698 | 3700 | | |
3699 | 3701 | | |
3700 | 3702 | | |
3701 | | - | |
3702 | | - | |
| 3703 | + | |
| 3704 | + | |
| 3705 | + | |
3703 | 3706 | | |
3704 | 3707 | | |
3705 | | - | |
| 3708 | + | |
3706 | 3709 | | |
3707 | 3710 | | |
3708 | | - | |
3709 | | - | |
| 3711 | + | |
| 3712 | + | |
3710 | 3713 | | |
3711 | | - | |
3712 | | - | |
| 3714 | + | |
| 3715 | + | |
3713 | 3716 | | |
3714 | | - | |
3715 | | - | |
| 3717 | + | |
| 3718 | + | |
3716 | 3719 | | |
3717 | | - | |
| 3720 | + | |
| 3721 | + | |
| 3722 | + | |
| 3723 | + | |
| 3724 | + | |
3718 | 3725 | | |
3719 | | - | |
3720 | | - | |
3721 | | - | |
3722 | | - | |
| 3726 | + | |
| 3727 | + | |
| 3728 | + | |
| 3729 | + | |
3723 | 3730 | | |
3724 | 3731 | | |
3725 | 3732 | | |
3726 | 3733 | | |
3727 | | - | |
3728 | | - | |
3729 | | - | |
3730 | | - | |
3731 | | - | |
3732 | | - | |
3733 | | - | |
| 3734 | + | |
| 3735 | + | |
| 3736 | + | |
3734 | 3737 | | |
3735 | 3738 | | |
3736 | | - | |
3737 | | - | |
3738 | | - | |
3739 | | - | |
3740 | | - | |
3741 | | - | |
3742 | | - | |
3743 | 3739 | | |
3744 | 3740 | | |
3745 | | - | |
3746 | | - | |
| 3741 | + | |
| 3742 | + | |
| 3743 | + | |
| 3744 | + | |
| 3745 | + | |
| 3746 | + | |
| 3747 | + | |
| 3748 | + | |
| 3749 | + | |
| 3750 | + | |
3747 | 3751 | | |
3748 | 3752 | | |
0 commit comments