The Inarticulate

A chaotic pinboard of unsorted notes

TAGS ▼
YEARS ▼
PROJECTS ▼
TAGS
  • #automation
  • #cloudflare
  • #docker
  • #life
  • #linux
  • #macos
  • #networking
  • #opensource
  • #performance
  • #proxy
  • #python
  • #rant
  • #regex
  • #shell
  • #ssh
  • #ubuntu
  • #vim
  • #vpn
  • #vps
YEARS
2026 2025 2021 2020 2017 2016 2013 2009 2007 2006
PROJECTS
ydiff View diff side by side
Gcal Exporter Export google calendar events
ipfw.net IP Lookup & Firewall Checker
tenuki Play on OGS from terminal
@ymattw

Your 1 GB VPS Is Enough for a Proxy

Nov 28, 2026

Following up on tuning a 1 GB proxy VPS : Caddy was originally in the stack for automatic TLS certificate management and the flexibility to host a real website alongside the proxy. Since I don’t actually need to host a website on a proxy VPS — and under load Caddy was burning ~55–60% of both proxy CPU and RAM just to sit between Cloudflare and Xray — I dropped it altogether and let Xray terminate TLS 1.3 + HTTP/2 + XHTTP directly, along with a few remaining OS and runtime tweaks. Everything below is backported into my VPS setup scripts .

Architecture Change

Before: Client → Cloudflare → Caddy (:443) → h2c (@xray) → Xray → Internet
After:  Client → Cloudflare → Xray (:443) → Internet

Dropping Caddy removes a second Go runtime/GC, internal h2c re-framing, and the @xray Unix-socket IPC copy:

  • 15-year ECC Cloudflare Origin CA cert (/opt/xray/{cert,key}.pem, SSL mode Full (Strict)): a one-time wildcard cert reusable across all subdomains, eliminating ACME renewal and Let’s Encrypt CT-log subdomain leakage.
  • Non-root :443 with full systemd hardening: setting net.ipv4.ip_unprivileged_port_start = 443 lets User=xray bind :443 with zero capabilities and PrivateUsers=yes intact.
  • Tighter UFW rules: :443/tcp only accepts Cloudflare’s published IPv4/IPv6 ranges, so direct IP scans are silently dropped.

Other Optimization Points

  • Go runtime & scheduling: dynamic GOMEMLIMIT computed from actual MemTotal (reserving max(448 MiB, 20%) for OS/kernel and an extra 1 GiB for Docker on ≥ 4 GB VMs), GOGC=200 on ≥ 2 GB VMs, plus OOMScoreAdjust=-500, Nice=-5, and CPUWeight=200 on xray.service.
  • Kernel, swap & I/O hygiene: persisted nf_conntrack in modules-load.d (fixing a boot-order skip of nf_conntrack_max), capped ip_local_port_range below 60000, switched zram from zstd to lz4 (lower CPU on burstable vCPUs) with tuned VM watermarks/dirty ratios, enabled noatime on /, disabled UFW drop logging, removed locate, and disabled man-db/e2scrub_all/multipathd.
  • Tested and left at default: mode=stream-up and stream-one fail behind Cloudflare (which buffers POST bodies at the edge), and tuning xmux (maxConnections=4 vs. default) showed only marginal tail-latency gains — so mode=auto and default xmux stayed untouched.

Results

Verified with A/B benchmarks on both identical OCI free-tier 1 GB VMs (1/8 OCPU, 50 Mbps NIC) and a NetCup 2c/4G VM constrained to 1 GB-equivalent conditions (2,730 MiB mlock RAM ballast + 1 GB GOMEMLIMIT + 16 MB TCP caps) up to 500 Mbps:

Metric (Caddy + Xray → Direct Xray) Before After Delta
Proxy CPU at ~485 Mbps (1-core, NetCup) 44.5% 22.0% −51% (~2× CPU eff.)
Proxy CPU at ~48 Mbps cap (1-core, OCI) 25.5% 10.8% −58%
Peak RPS on 1/8 OCPU (OCI) 78.4 rps 118.0 rps +51% (at lower CPU)
Proxy RSS / private RAM at 485 Mbps 123 / 67 MiB 39 / 13 MiB −68% / −81%
Proxy RSS / private RAM under mixed load 169 / 113 MiB 48 / 21 MiB −72% / −81% (+107M free)
Unloaded / loaded p50 latency (NetCup) 41 / 50 ms 32 / 41 ms −21% / −19%

Removing Caddy cut proxy CPU roughly in half and private RAM by 70–80% while simplifying the stack to a single hardened binary — leaving plenty of headroom even on a 1 GB VPS.

#linux #networking #performance #vps