From ce38f6aaa7898ae0d3bab12b22ab083d3c059090 Mon Sep 17 00:00:00 2001 From: tbphp Date: Fri, 11 Jul 2025 21:57:40 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/channel/factory.go | 10 ++-------- internal/types/types.go | 16 ++++++++-------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/internal/channel/factory.go b/internal/channel/factory.go index 07ccbfb..322df55 100644 --- a/internal/channel/factory.go +++ b/internal/channel/factory.go @@ -132,14 +132,8 @@ func (f *Factory) newBaseChannel(name string, group *models.Group) (*BaseChannel streamConfig.WriteBufferSize = 0 streamConfig.ReadBufferSize = 0 // Use a larger, independent connection pool for streaming clients to avoid exhaustion. - streamConfig.MaxIdleConns = group.EffectiveConfig.MaxIdleConns * 2 - if streamConfig.MaxIdleConns < 200 { - streamConfig.MaxIdleConns = 200 - } - streamConfig.MaxIdleConnsPerHost = group.EffectiveConfig.MaxIdleConnsPerHost * 2 - if streamConfig.MaxIdleConnsPerHost < 40 { - streamConfig.MaxIdleConnsPerHost = 40 - } + streamConfig.MaxIdleConns = max(group.EffectiveConfig.MaxIdleConns*2, 50) + streamConfig.MaxIdleConnsPerHost = max(group.EffectiveConfig.MaxIdleConnsPerHost*2, 20) // Get both clients from the manager using their respective configurations. httpClient := f.clientManager.GetClient(clientConfig) diff --git a/internal/types/types.go b/internal/types/types.go index 97d522e..39f7d4c 100644 --- a/internal/types/types.go +++ b/internal/types/types.go @@ -18,20 +18,20 @@ type ConfigManager interface { type SystemSettings struct { // 基础参数 AppUrl string `json:"app_url" default:"http://localhost:3000" name:"项目地址" category:"基础参数" desc:"项目的基础 URL,用于拼接分组终端节点地址。系统配置优先于环境变量 APP_URL。"` - RequestLogRetentionDays int `json:"request_log_retention_days" default:"7" name:"日志保留天数" category:"基础参数" desc:"请求日志在数据库中的保留天数" validate:"min=0"` + RequestLogRetentionDays int `json:"request_log_retention_days" default:"7" name:"日志保留时长(天)" category:"基础参数" desc:"请求日志在数据库中的保留天数" validate:"min=0"` // 请求设置 - RequestTimeout int `json:"request_timeout" default:"600" name:"请求超时" category:"请求设置" desc:"转发请求的完整生命周期超时(秒),包括连接、重试等。" validate:"min=1"` - ConnectTimeout int `json:"connect_timeout" default:"30" name:"连接超时" category:"请求设置" desc:"与上游服务建立新连接的超时时间(秒)。" validate:"min=1"` - IdleConnTimeout int `json:"idle_conn_timeout" default:"120" name:"空闲连接超时" category:"请求设置" desc:"HTTP 客户端中空闲连接的超时时间(秒)。" validate:"min=1"` - ResponseHeaderTimeout int `json:"response_header_timeout" default:"120" name:"响应头超时" category:"请求设置" desc:"等待上游服务响应头的最长时间(秒),用于流式请求。" validate:"min=1"` - MaxIdleConns int `json:"max_idle_conns" default:"50" name:"最大空闲连接数" category:"请求设置" desc:"HTTP 客户端连接池中允许的最大空闲连接总数。" validate:"min=1"` - MaxIdleConnsPerHost int `json:"max_idle_conns_per_host" default:"20" name:"每主机最大空闲连接数" category:"请求设置" desc:"HTTP 客户端连接池对每个上游主机允许的最大空闲连接数。" validate:"min=1"` + RequestTimeout int `json:"request_timeout" default:"600" name:"请求超时(秒)" category:"请求设置" desc:"转发请求的完整生命周期超时(秒),包括连接、重试等。" validate:"min=1"` + ConnectTimeout int `json:"connect_timeout" default:"15" name:"连接超时(秒)" category:"请求设置" desc:"与上游服务建立新连接的超时时间(秒)。" validate:"min=1"` + IdleConnTimeout int `json:"idle_conn_timeout" default:"120" name:"空闲连接超时(秒)" category:"请求设置" desc:"HTTP 客户端中空闲连接的超时时间(秒)。" validate:"min=1"` + ResponseHeaderTimeout int `json:"response_header_timeout" default:"15" name:"响应头超时(秒)" category:"请求设置" desc:"等待上游服务响应头的最长时间(秒),用于流式请求。" validate:"min=1"` + MaxIdleConns int `json:"max_idle_conns" default:"100" name:"最大空闲连接数" category:"请求设置" desc:"HTTP 客户端连接池中允许的最大空闲连接总数。" validate:"min=1"` + MaxIdleConnsPerHost int `json:"max_idle_conns_per_host" default:"50" name:"每主机最大空闲连接数" category:"请求设置" desc:"HTTP 客户端连接池对每个上游主机允许的最大空闲连接数。" validate:"min=1"` // 密钥配置 MaxRetries int `json:"max_retries" default:"3" name:"最大重试次数" category:"密钥配置" desc:"单个请求使用不同 Key 的最大重试次数" validate:"min=0"` BlacklistThreshold int `json:"blacklist_threshold" default:"3" name:"黑名单阈值" category:"密钥配置" desc:"一个 Key 连续失败多少次后进入黑名单" validate:"min=0"` - KeyValidationIntervalMinutes int `json:"key_validation_interval_minutes" default:"60" name:"定时验证周期" category:"密钥配置" desc:"后台定时验证密钥的默认周期(分钟)" validate:"min=30"` + KeyValidationIntervalMinutes int `json:"key_validation_interval_minutes" default:"60" name:"定时验证周期(分钟)" category:"密钥配置" desc:"后台定时验证密钥的默认周期(分钟)" validate:"min=30"` } // ServerConfig represents server configuration