refactor: 优化指标统计逻辑,减少锁的使用,提高性能

This commit is contained in:
2026-03-06 12:18:43 +08:00
parent 0f2d550a14
commit a6ed3f8f4c
6 changed files with 63 additions and 152 deletions

12
main.go
View File

@@ -50,8 +50,16 @@ func main() {
if cfg.Debug || lvlStr == "debug" { gin.SetMode(gin.DebugMode) } else { gin.SetMode(gin.ReleaseMode) }
// 可复用的 HTTP 客户端(保持连接复用)
transport := &http.Transport{Proxy: http.ProxyFromEnvironment, DisableCompression: true}
// 可复用的 HTTP 客户端
transport := &http.Transport{
Proxy: http.ProxyFromEnvironment,
ForceAttemptHTTP2: true,
MaxIdleConns: 512,
MaxIdleConnsPerHost: 128,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
}
client := &http.Client{Transport: transport}
if cfg.RequestTimeout > 0 { client.Timeout = time.Duration(cfg.RequestTimeout) * time.Second }