/etc/security/limits.conf
,设置* soft nofile 65536
和* hard nofile 65536
。/etc/sysctl.conf
,调整net.core.somaxconn
、tcp_max_syn_backlog
等参数,提升网络性能。export GOMAXPROCS=8
,优化CPU调度。GOGC
环境变量(如export GOGC=150
)控制GC触发频率,或使用sync.Pool
减少内存分配压力。sync.Pool
复用对象,避免循环中创建临时对象。channel
、goroutine
池,避免过多goroutine
导致调度开销。map
替代slice
进行快速查找,用strings.Builder
优化字符串拼接。-ldflags="-s -w"
减少二进制体积,-buildcache
开启编译缓存。pprof
工具定位CPU/内存瓶颈,针对性优化。