perf(postgres): 分离 API 池并降低连接预热
生产同构千并发请求在干净队列上复现 API Pool 31/32、idle=1 且 canceled acquire 持续增长,Worker Pool 仅使用少量连接,确认瓶颈位于 API 数据库连接预算而非 Worker 执行槽。 新增可配置的 AI_GATEWAY_DATABASE_MIN_IDLE_CONNS,生产仅预热 4 条连接;API Pool 独立固定为 48,Worker Pool 继续跟随 P24/P28/P32 的 32/36/40 档位。发布工具、Kubernetes 清单、验收门禁和文档同步更新。 验证:Go 全量测试、gofmt、bash -n、ShellCheck、kubectl kustomize 和 git diff --check 通过。
This commit is contained in:
@@ -27,7 +27,7 @@ func TestPostgresPoolConfigRejectsMalformedURL(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPostgresPoolConfigWarmsBoundedIdleConnections(t *testing.T) {
|
||||
func TestPostgresPoolConfigUsesExplicitMinimumIdleConnections(t *testing.T) {
|
||||
config, err := postgresPoolConfig(
|
||||
"postgresql://gateway:password@localhost:5432/gateway?sslmode=disable",
|
||||
24,
|
||||
@@ -35,23 +35,23 @@ func TestPostgresPoolConfigWarmsBoundedIdleConnections(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("parse PostgreSQL pool config: %v", err)
|
||||
}
|
||||
if config.MaxConns != 24 || config.MinIdleConns != 24 {
|
||||
if config.MaxConns != 24 || config.MinIdleConns != 0 {
|
||||
t.Fatalf(
|
||||
"pool bounds max=%d minIdle=%d, want 24/24",
|
||||
"pool bounds max=%d minIdle=%d, want 24/0",
|
||||
config.MaxConns,
|
||||
config.MinIdleConns,
|
||||
)
|
||||
}
|
||||
|
||||
small, err := postgresPoolConfig(
|
||||
warmed, err := postgresPoolConfigWithOptions(
|
||||
"postgresql://gateway:password@localhost:5432/gateway?sslmode=disable",
|
||||
4,
|
||||
PostgresPoolOptions{MaxConns: 24, MinIdleConns: 4},
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("parse small PostgreSQL pool config: %v", err)
|
||||
t.Fatalf("parse warmed PostgreSQL pool config: %v", err)
|
||||
}
|
||||
if small.MinIdleConns != 4 {
|
||||
t.Fatalf("small pool minIdle=%d, want 4", small.MinIdleConns)
|
||||
if warmed.MinIdleConns != 4 {
|
||||
t.Fatalf("warmed pool minIdle=%d, want 4", warmed.MinIdleConns)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +60,7 @@ func TestPostgresPoolConfigSetsBoundedTransactionTimeouts(t *testing.T) {
|
||||
"postgresql://gateway:password@localhost:5432/gateway?sslmode=disable",
|
||||
PostgresPoolOptions{
|
||||
MaxConns: 32,
|
||||
MinIdleConns: 4,
|
||||
IdleInTransactionTimeout: 60 * time.Second,
|
||||
LockTimeout: 30 * time.Second,
|
||||
},
|
||||
@@ -73,8 +74,8 @@ func TestPostgresPoolConfigSetsBoundedTransactionTimeouts(t *testing.T) {
|
||||
if got := config.ConnConfig.RuntimeParams["lock_timeout"]; got != "30000ms" {
|
||||
t.Fatalf("lock timeout = %q, want 30000ms", got)
|
||||
}
|
||||
if config.MaxConns != 32 || config.MinIdleConns != 32 {
|
||||
t.Fatalf("pool bounds max=%d minIdle=%d, want 32/32", config.MaxConns, config.MinIdleConns)
|
||||
if config.MaxConns != 32 || config.MinIdleConns != 4 {
|
||||
t.Fatalf("pool bounds max=%d minIdle=%d, want 32/4", config.MaxConns, config.MinIdleConns)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user