Introduction

Running Trojan-based VPN services on Cloud VPS instances can deliver excellent performance and stealth, but out-of-the-box deployments often leave significant headroom untapped. This guide walks through practical, field-tested performance tuning techniques for Trojan (including trojan-go or trojan-gfw variants) on common cloud VPS platforms. The focus is on maximizing throughput, reducing latency, and improving stability for site owners, operators, and developers who need predictable, high-performance VPN endpoints.

Understand the Performance Constraints

Before tuning, profile your environment. Performance bottlenecks typically fall into three categories:

  • Network (bandwidth, packet processing, MTU, latency)
  • CPU and I/O (encryption overhead, syscall rates, context switches)
  • Software stack (TLS settings, concurrency, process model, proxies like Nginx)

Run simple measurements first: iperf3 between client and VPS, tcptraceroute or mtr for path analysis, and small-scale load tests using multiple concurrent connections. This baseline informs which tunables matter for your setup.

Kernel and Network Stack Tuning

The Linux kernel network stack is a primary lever for throughput and packet handling. Apply these sysctl changes to reduce packet loss, increase buffer capacity, and improve TCP behavior under load.

Essential sysctl settings

Adjust sysctl values in /etc/sysctl.conf or via sysctl -w. Key parameters:

  • net.core.rmem_max and net.core.wmem_max: Increase to allow larger socket buffers for high-bandwidth links (e.g., 16MB).
  • net.core.netdev_max_backlog: Raise to handle bursts on virtual NICs (e.g., 250000).
  • net.ipv4.tcp_rmem and net.ipv4.tcp_wmem: Configure min, default, max to support autotuning (e.g., 4096 87380 16777216).
  • net.ipv4.tcp_congestion_control: Use a modern algorithm like bbr (see below) or fq_codel queue discipline.
  • net.core.somaxconn and net.ipv4.tcp_max_syn_backlog: Increase to support more simultaneous handshakes.

Example (values to tune per VPS):

Recommended baseline: net.core.rmem_max=16777216; net.core.wmem_max=16777216; net.core.netdev_max_backlog=250000; net.ipv4.tcp_rmem=4096 87380 16777216; net.ipv4.tcp_wmem=4096 87380 16777216.

Enable BBR congestion control

BBR typically improves throughput and latency for long-distance links. Check kernel support with sysctl net.ipv4.tcp_congestion_control and add bbr as default:

Command: sysctl -w net.ipv4.tcp_congestion_control=bbr

Also ensure the kernel has bbr (Linux 4.9+). Confirm with lsmod | grep bbr or ss -t -i under load to observe RTT improvements.

Offloading and IRQ affinity

Cloud NICs often support offloads like GRO/TSO/LRO which can help CPU usage. However, on some virtualized environments they can harm latency — test both states. Use ethtool to toggle. For multi-core VPS, set IRQ affinity to distribute NIC interrupts across vCPUs.

Commands (examples): ethtool -K eth0 gro off; echo 2 > /proc/irq//smp_affinity

TLS and Trojan Configuration

TLS is central to Trojan’s security and performance. Proper TLS setup reduces CPU load, avoids handshaking overhead, and improves connection reuse.

Use modern ciphers and TLS 1.3

Enable TLS 1.3 and prefer AEAD ciphers (e.g., TLS_AES_128_GCM_SHA256). TLS 1.3 reduces round-trips and supports faster handshakes. For trojan-go or similar, ensure the underlying Go runtime supports TLS 1.3 (Go 1.12+).

Key points:

  • Prefer ECDSA certificates (P-256) to reduce CPU signing cost if supported by clients.
  • Enable session resumption (tickets) to avoid repeated full handshakes.
  • Use an OCSP stapling-capable server to reduce client validation latency.

TLS session tickets and key rotation

Configure stateless session tickets so resumed sessions bypass expensive handshakes. For server processes, use a shared ticket key file when running multiple instances behind a load balancer. Rotate keys periodically but maintain an overlap to allow resumption.

Operational note: If using multiple VPS or autoscaling, synchronize ticket keys via secure channels to preserve session resumption across instances.

Offload TLS if needed

If CPU encryption becomes the bottleneck, consider a reverse proxy (Nginx or Caddy) terminating TLS and forwarding to Trojan locally over a short loopback connection. This approach centralizes TLS optimizations like session caching and OCSP stapling. However, it adds another hop — weigh benefits with your latency budget.

Process and Concurrency Tuning

Trojan and trojan-go are multi-connection servers; process model and file descriptor limits matter.

Ulimits and file descriptors

Raise file descriptor limits for the Trojan process to support many concurrent connections:

  • Set /etc/security/limits.conf for the trojan user: nofile soft/hard 200000
  • Systemd users: set LimitNOFILE=200000 in the service unit

Golang runtime settings (for trojan-go)

Trojan-go is Go-based; the Go scheduler and GC can be tuned with environment variables. For high network throughput:

  • Set GOMAXPROCS to number of vCPUs for best concurrency.
  • Use GODEBUG=gctrace=1 for debugging GC pauses under load.

Connection multiplexing and keepalive

Enable keepalive and multiplexing where supported to reduce connection establishment overhead. Trojan-go supports multiplexing modes (mux). Multiplexing reduces per-connection TLS and TCP overhead, improving throughput for many short-lived streams.

MTU, MSS Clamping and Path MTU

Incorrect MTU leads to fragmentation and retransmissions. For VPN protocols tunneled over TLS/HTTPS, ensure the MTU accommodates extra headers. Typical steps:

  • Discover path MTU: use ping with various packet sizes and DF bit.
  • Set MTU on client-facing interfaces to avoid fragmentation: e.g., if underlying interface is 1500 and TLS adds ~100 bytes, reduce to 1400 or clamp MSS via iptables.

iptables MSS clamping example: iptables -t mangle -A FORWARD -p tcp –tcp-flags SYN,RST SYN -j TCPMSS –clamp-mss-to-pmtu

Reverse Proxy and Load Balancing Considerations

Many operators deploy Nginx or a CDN in front of Trojan. When doing so, tune the proxy for idle timeouts, buffer sizes, and worker processes.

  • Set worker_processes to auto and worker_connections high enough to cover expected concurrency.
  • Use proxy_buffering off for long-lived streams or set large proxy buffers if streaming.
  • Use keepalive between proxy and Trojan backend to avoid repeated TCP/TLS setups.

If using a load balancer, prefer layer 4 pass-through (TCP) to avoid TLS termination overhead unless you intentionally want the proxy to handle TLS.

Monitoring, Testing and Continuous Tuning

Tuning is iterative. Instrument the stack with metrics and routinely test under realistic loads.

Key metrics

  • CPU utilization per core (top, mpstat)
  • Context switches and interrupts (vmstat, pidstat)
  • Network errors, drops, retransmits (ifconfig, ss -s)
  • Application-level latency and throughput (custom clients, wrk/tsung)

Load testing approach

Simulate realistic client patterns: a mix of long-lived and short-lived connections, variable payload sizes, and different geographic sources. Measure the 95th and 99th percentile latencies, not just averages. Use tcpdump or Wireshark to inspect TLS handshake behavior and retransmissions.

Practical Checklist Before Production

  • Baseline measurements (iperf3, mtr) collected.
  • sysctl tuned and persisted; BBR enabled if supported.
  • Socket buffers adjusted and somaxconn raised.
  • uLimits set and systemd unit adjusted for trojan process.
  • TLS configured with TLS 1.3, AEAD ciphers, session tickets, and ECDSA where practical.
  • MTU validated and MSS clamping enabled if required.
  • Monitoring and alerting for CPU, network, and application metrics in place.

Troubleshooting Common Issues

High CPU with many connections

If CPU is saturated and throughput is low, consider:

  • Enabling or tuning TLS offload/acceleration where supported by the cloud provider.
  • Using ECDSA certs to reduce RSA signing overhead.
  • Sharding services across more VPS instances with a load balancer and shared TLS ticket/key configuration.

Packet loss or high retransmits

Investigate MTU mismatches, NIC offload settings, and noisy network paths. Temporarily disabling TSO/GRO on the NIC may reveal whether offloads are the culprit.

Conclusion

Optimizing Trojan on a Cloud VPS is a systems engineering effort: balance kernel tunables, TLS choices, process limits, and network-layer settings. Start with measurement, apply focused changes (BBR, socket buffers, TLS 1.3, ulimits, and MTU/MSS adjustments), and iterate with realistic load tests. With disciplined tuning you can significantly improve throughput and reduce latency, delivering a robust VPN experience for your users.

For more advanced deployment patterns and guides tailored to VPS providers, visit Dedicated-IP-VPN at https://dedicated-ip-vpn.com/