Tuning a 1 GB Proxy VPS: 5× Throughput, Half the Latency, Half the RAM
I run my personal proxy stack (VLESS + TLS (Caddy) + Cloudflare CDN) on a
cheap GCP e2-micro VM — 2 shared vCPUs (0.25 vCPU sustained baseline), 964 MiB
RAM, zero swap, Debian 13, sitting in Taiwan (asia-east1-b). Connecting from
Switzerland gives ~8 ms to Cloudflare’s Zurich edge and ~250 ms across the long
transcontinental leg to Taiwan.
It worked fine, but I had never actually measured or tuned it. So I spun up two
identical e2-micro VMs in the same zone — keeping tw1 untouched as the
baseline and tuning tw2 one layer at a time with interleaved A/B benchmarks.
An initial A/A run confirmed both unmodified servers behaved identically: ~31
Mbps single-stream download, ~17 Mbps upload, ~21–28 Mbps across 6 parallel
downloads, ~1,800 ms median cold TTFB, and 478 MiB idle available RAM.
Everything below ended up backported into my VPS setup scripts .
Layer 1: Linux Kernel & TCP Stack (BBR + fq)
With ~250 ms RTT between Cloudflare’s edge and GCP Taiwan, default cubic
congestion control, 208 KB socket caps, tcp_slow_start_after_idle = 1, and an
8,192-entry conntrack table left massive bandwidth on the table.
We switched to BBR
(Bottleneck
Bandwidth and Round-trip propagation time) — Google’s model-based TCP congestion
control algorithm that estimates the path’s bandwidth and minimum RTT to pace
sending instead of filling router queues until packets drop like cubic —
paired with fq
(Fair
Queueing), the Linux packet scheduler that provides the per-flow packet pacing
BBR relies on to avoid micro-bursts.
In /etc/sysctl.d/99-proxy-tuning.conf (with tcp_bbr persisted in
/etc/modules-load.d/bbr.conf and tc qdisc replace dev <iface> root fq so
pacing takes effect without a reboot):
- Congestion control & pacing:
net.core.default_qdisc = fqandnet.ipv4.tcp_congestion_control = bbr. - RAM-scaled buffers & conntrack: 16 MB max TCP/UDP buffers and 65,536 conntrack entries on 1 GB VMs, scaling to 32 MB / 131k on 2 GB and 64 MB / 262k on 4 GB+.
- Persistent proxy tuning:
tcp_slow_start_after_idle = 0,tcp_fastopen = 3,tcp_mtu_probing = 1,tcp_notsent_lowat = 131072,somaxconn = 8192,netdev_max_backlog = 8192. (In Linux,net.ipv4.tcp_*applies to both IPv4 and IPv6 TCP sockets.)
Result vs. baseline: single-stream DL +23% (29.5 → 36.4 Mbps), upload +9%,
6-stream DL +93% (23.5 → 45.5 Mbps), and TCP retransmits dropped -75%
(0.28% → 0.07%).
Layer 2: Eliminating the Local Proxy Hop (unix/@xray)
Previously, every packet between Caddy and Xray traversed:
Caddy → 127.0.0.1:60066 → docker-proxy (userland copy) → docker0 veth → iptables NAT → Xray
Switching Xray to an abstract Unix domain socket (listen: "@xray",
reverse_proxy unix/@xray) removed docker-proxy, bridge NAT, loopback TCP,
and ephemeral port churn in one move. Stripping X-Forwarded-For on the reverse
proxy also stopped Xray from writing a warning to disk on every connection.
Result: 6-stream download jumped from 28.1 → 95.4 Mbps (+239%, peaking at 102 Mbps) while using ~50% fewer conntrack entries, ~30% fewer TCP segments, and slightly lower CPU than the baseline.
Layer 3: Migrating WebSocket to XHTTP (H2)
Even at 95 Mbps, cold HTTPS latency stayed stubbornly stuck at ~1,800 ms and connection churn capped at ~9 rps. Why? Because HTTP/1.1 WebSocket cannot be multiplexed over a single origin connection behind Cloudflare — every new proxied flow pays origin TCP+TLS setup plus a WebSocket Upgrade round-trip across 250 ms RTT.
- Quick test — WebSocket Early Data (
?ed=2048): piggybacking the VLESS header on the WS upgrade request (client-only change) immediately cut 365 ms off median latency (1,801 → 1,436 ms, -20%) and boosted churn by +26%. - Full upgrade — VLESS + XHTTP over HTTP/2 (
h2c): with XHTTP (route /$route*andtransport http { versions h2c 2 }in Caddy,alpn: ["h2"]on the client), bothClient ↔ CloudflareandCloudflare ↔ Caddymultiplex streams over warm HTTP/2 connections.
| Metric | Baseline (WS) | Tuned WS | WS + ?ed=2048 |
XHTTP (H2) |
|---|---|---|---|---|
| Latency p50 | 1,793 ms | 1,818 ms | 1,436 ms | 764 ms (-57%) |
| Latency p95 | 1,945 ms | 1,929 ms | 1,517 ms | 1,033 ms (-47%) |
| Churn (16 conc) | 9.1 rps | 9.2 rps | 11.2 rps | 18.4 rps (2.0×) |
| 6-stream DL | 28.5 Mbps | 86.8 Mbps | 74.3 Mbps | 155.0 Mbps (5.4×) |
| 1-stream DL | 32.4 Mbps | 37.6 Mbps | 39.3 Mbps | 42.1 Mbps (peak 96.6) |
| TCP Retransmits | 0.10% | 0.00% | 0.02% | 0.00% |
Cold TTFB dropped by over a full second, and Xray’s WebSocket deprecation
warning disappeared. We also replaced the hardcoded URL path with the first
segment of the generated UUID (${uuid%%-*}) and appended &tfo=1 to the
Shadowrocket QR URI so TCP Fast Open enables automatically on scan.
Layer 4: Putting a 1 GB VM on a Memory Diet
Next, I simulated 3 heavy concurrent devices (continuous downloads, 4K video
chunks, uploads, and 12 browser request loops plus an active tmux session)
with 1-second server telemetry — then pushed it to 60 concurrent streams to see
where a 964 MiB e2-micro actually breaks.
The biggest surprise wasn’t Xray or Caddy — it was the OS itself. Nearly half the VM (~470 MiB) was already gone before proxy traffic even started:
- 6 GCP guest/telemetry agents:
~145 MiBRSS (google-osconfig-agent,google-guest-compat-manager,google-guest-agent-managerplus its workload identity and telemetry plugins). - Docker runtime:
~140–160 MiBRSS (dockerd+containerd+ shim) just to wrap a single static Go binary running with--network=host. - Redundant daemons:
haveged(obsolete on Linux 6.12),networkd-dispatcher, andrsyslog(redundant withsystemd-journald).
Here is what actually moved the needle:
- Disabled unused background services (keeping
unattended-upgradesfor kernel security patches, and stoppinggoogle-guest-agent-managerafter a 15-second background delay so GCE first-boot startup scripts still complete cleanly). Verified across a full reboot that SSH andsystemd-networkdDHCP come straight back up. - Replaced Docker with a hardened native
systemdservice: Docker andsystemduse the same Linux kernel isolation primitives. Running Xray directly under a dedicatedxraysystem user withNoExecPaths=/,ExecPaths=/opt/xray/xray,MemoryDenyWriteExecute=yes,CapabilityBoundingSet=(zero caps),PrivateUsers=yes,ProtectSystem=strict,ProtectProc=invisible,SystemCallFilter=@system-service, and read-onlyconfig.jsonscored1.1 OK :-)onsystemd-analyze security xray.service— matching or beatingdocker --network=hostwhile reclaiming ~150 MiB and removing a root daemon. (One subtle catch:ProcSubset=pidhid/proc/sys/net/core/somaxconnfrom Go, silently dropping the@xraylisten backlog from 8,192 to 128 — droppingProcSubset=pidwhile keepingProtectProc=invisiblerestored 8,192 with the same1.1 OKscore.) - Trimmed Caddy: Disabled Caddy’s unused HTTP/3 UDP
:443listener (servers { protocols h1 h2 }— Cloudflare never uses H3 to origins), set globallog { level ERROR }, dropped Debian’s default:80file server, and shrunk theh2cupstream pool (32 KBbuffers,30skeepalive,16idle conns). - Added 512 MB
zstdzramswap (systemd-zram-generator,vm.page-cluster = 0,vm.swappiness = 100, plusjournaldcapped at 32 MB). Under pressure, cold pages compressed at 11:1–15:1 (28 MiBinto2.5 MiBof RAM) with zero disk I/O.
Memory Metric (e2-micro, 964 MiB) |
Before (Docker + GCP agents + 0 swap) | After (Native systemd + trimmed + zram) |
|---|---|---|
Idle MemAvailable |
478 MiB | 704 MiB (+226 MiB) |
| OS + Kernel peak (3 heavy devices) | 469–511 MiB | 249 MiB (-50%) |
Min MemAvailable (3 heavy devices) |
273 MiB | 509 MiB (+86%) |
Min MemAvailable (60 streams) |
48.5 MiB (near OOM) | 213.5 MiB (4.4×) |
| Memory PSI (60 streams) | 6.8–10.1 | 0.36 (~25× lower) |
We also measured GOMEMLIMIT (finding a consistent 60% Caddy / 40% Xray usage
split across every load level), but with ~670–700 MiB free and 512 MB of zram
on a 1 GB VM, OOM is no longer a realistic risk — so we kept GOMEMLIMIT on a
side branch rather than adding complexity prematurely.
Final Numbers (and One Bonus Lesson)
From start to finish on the exact same ~$7/month e2-micro:
- Cold latency (p50):
1,793 ms → 764 ms(-57%) - 6-stream burst throughput:
28.5 Mbps → 155–167 Mbps(5.4×; peaked at 248 Mbps DL + 38 Mbps UL in 60-second multi-device stress while CPU burst credits lasted, before settling to ~35–60 Mbps at the 0.25 vCPU sustained baseline) - TCP retransmits:
0.10–0.28% → 0.00%in standard benchmarks (0.04–0.21%under heavy multi-device saturation) - Available RAM (idle):
478 MiB → ~670–704 MiB(Caddy37 MiB+ Xray34 MiBfresh)
And one unexpected takeaway: pushing 60 concurrent HTTPS streams (~295 Mbps
outbound burst) through an e2-micro to public speed-test endpoints was
effective enough to trigger a Google Cloud Trust & Safety DoS alert twenty
minutes later. Measure your changes, keep your load tests realistic, and don’t
accidentally DDoS-alert yourself.