How can I optimize my Caddy config for V2RAY?

Hello There ,

I have installed V2RAY ( VMESS + Websocket + TLS ) via a script and that script has installed caddy as the web server . Unfortunately , when the number of connections go up , both memory and CPU usage go through the roof and the clients can’t browse web anymore . the " top " command on Ubuntu shows that CPU and RAM usage is 100% ( all consumed by caddy ) . Is there anyway to optimize caddy so that we can reduce RAM and CPU usage ? I’m pretty sure the default config is not doing anything in terms of optimization.

1. Output of caddy version:

v2.6.2

2. How I run Caddy:

it’s installed as via a scripts to pass requests to V2RAY .

a. System environment:

Ubuntu 18 server (KVM) and it’s not a docker container .

d. My complete Caddy config:

vrpl3.dehoster.info {
    reverse_proxy https://yummyistanbul.com {
        header_up Host {upstream_hostport}
        header_up X-Forwarded-Host {host}
    }
    handle_path /8snasdr9 {
        reverse_proxy 127.0.0.1:59397
    }
}
import sites/*

VPS server has 4 GB of RAM and 2 Cores CPU @2.4 GHz

Any help would be appreciated , thank you .

Remove this. Caddy sets this header automatically now.

What’s in these sites?

That’s surprising. You’ll probably need to get a profile from Caddy to see what’s causing this.

@matt knows the details better than I for getting a profile.

1 Like

You can access http://localhost:2019/debug/pprof to collect a profile; you can also get goroutine dumps to see where the program is executing at any given moment. The heap profiles will tell you where most of the allocations are coming from.