[PR #7037] [CLOSED] perf(amneziawg): reuse relay buffers, bound the bridge connect time #6592

Closed
opened 2026-11-02 04:09:55 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/7037
Author: @Dv2Corn
Created: 11/1/2026
Status: ❌ Closed

Base: main ← Head: perf/amneziawg-relay-buffers


📝 Commits (4)

  • 0f555af amneziawg: reuse relay buffers, bound the bridge connect time
  • 3565b47 test(amneziawg): bound and reset of the bridge CONNECT deadline
  • e05cf65 test(amneziawg): no shared buffer between test goroutines; skip the pool check under -race
  • 3c2f447 fix(amneziawg): keep the raw bridge conn so a client half-close reaches upstream

📊 Changes

6 files changed (+464 additions, -10 deletions)

View changed files

📝 internal/amneziawgnet/egress.go (+2 -2)
➕ internal/amneziawgnet/race_off_test.go (+5 -0)
➕ internal/amneziawgnet/race_on_test.go (+5 -0)
📝 internal/amneziawgnet/relay.go (+59 -8)
➕ internal/amneziawgnet/relay_halfclose_test.go (+214 -0)
📝 internal/amneziawgnet/relay_test.go (+179 -0)

📄 Description

Every connection through the built-in AmneziaWG allocated two new 32 KiB buffers: net.TCPConn bypasses the buffer passed to io.CopyBuffer via ReadFrom/WriteTo. Under a stream of short connections this is gigabytes of garbage and a bloated panel heap.

Buffers now come from a sync.Pool, and the SOCKS handshake with the Xray bridge is limited to 10 s so a silent core cannot hold a connection.

Load test (300 AWG + 300 VLESS clients, 200 short connections/s through AWG, 15 min): panel memory average 462 MB → 240 MB, peak 510 → 250 MB. Heap profile before the fix: ~5.1 GB allocated in io.copyBuffer.

Tests: internal/amneziawgnet/relay_test.go; go test ./internal/amneziawgnet/... passes.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/7037 **Author:** [@Dv2Corn](https://github.com/Dv2Corn) **Created:** 11/1/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `perf/amneziawg-relay-buffers` --- ### 📝 Commits (4) - [`0f555af`](https://github.com/MHSanaei/3x-ui/commit/0f555af2387fd6afc58df4cd9392900c6b66a983) amneziawg: reuse relay buffers, bound the bridge connect time - [`3565b47`](https://github.com/MHSanaei/3x-ui/commit/3565b47997dd26b7e074b904071e973a71297911) test(amneziawg): bound and reset of the bridge CONNECT deadline - [`e05cf65`](https://github.com/MHSanaei/3x-ui/commit/e05cf65e1392fd0faff4485ed267892d0771b705) test(amneziawg): no shared buffer between test goroutines; skip the pool check under -race - [`3c2f447`](https://github.com/MHSanaei/3x-ui/commit/3c2f447a2bb863973e38e6cf93624715b296e761) fix(amneziawg): keep the raw bridge conn so a client half-close reaches upstream ### 📊 Changes **6 files changed** (+464 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `internal/amneziawgnet/egress.go` (+2 -2) ➕ `internal/amneziawgnet/race_off_test.go` (+5 -0) ➕ `internal/amneziawgnet/race_on_test.go` (+5 -0) 📝 `internal/amneziawgnet/relay.go` (+59 -8) ➕ `internal/amneziawgnet/relay_halfclose_test.go` (+214 -0) 📝 `internal/amneziawgnet/relay_test.go` (+179 -0) </details> ### 📄 Description Every connection through the built-in AmneziaWG allocated two new 32 KiB buffers: `net.TCPConn` bypasses the buffer passed to `io.CopyBuffer` via `ReadFrom`/`WriteTo`. Under a stream of short connections this is gigabytes of garbage and a bloated panel heap. Buffers now come from a `sync.Pool`, and the SOCKS handshake with the Xray bridge is limited to 10 s so a silent core cannot hold a connection. Load test (300 AWG + 300 VLESS clients, 200 short connections/s through AWG, 15 min): panel memory average 462 MB → 240 MB, peak 510 → 250 MB. Heap profile before the fix: ~5.1 GB allocated in `io.copyBuffer`. Tests: `internal/amneziawgnet/relay_test.go`; `go test ./internal/amneziawgnet/...` passes. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:09:55 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#6592
No description provided.