缓解io压力

This commit is contained in:
2026-09-02 16:14:27 +08:00
parent 395e5fb47c
commit dbfeeee253
17 changed files with 181 additions and 144 deletions

View File

@@ -169,7 +169,9 @@ type GatewayConfig struct {
type WorkerConfig struct {
Role string `mapstructure:"role"` // Worker 运行角色all、leader、consumer
InstanceName string `mapstructure:"instance_name"` // Worker 实例名称,用于多实例日志区分
PollingTotalMaxConcurrency int `mapstructure:"polling_total_max_concurrency"` // 全部轮询总并发上限
AuditRetentionCleanupEnabled bool `mapstructure:"audit_retention_cleanup_enabled"` // 是否启用审计日志物理清理
AuditArchiveTasksEnabled bool `mapstructure:"audit_archive_tasks_enabled"` // 是否启用审计归档与日留存任务
}
// ApprovalConfig 审批新旧入口切换配置。
@@ -382,6 +384,10 @@ func (c *Config) Validate() error {
constants.WorkerRoleLeader: true,
constants.WorkerRoleConsumer: true,
}
if c.Worker.PollingTotalMaxConcurrency < 1 || c.Worker.PollingTotalMaxConcurrency > constants.PollingMaxConcurrencyLimit {
return fmt.Errorf("invalid configuration: worker.polling_total_max_concurrency: must be 1-%d (current value: %d)", constants.PollingMaxConcurrencyLimit, c.Worker.PollingTotalMaxConcurrency)
}
if !validWorkerRoles[c.Worker.Role] {
return fmt.Errorf(
"invalid configuration: worker.role: invalid worker role (current value: %s, expected: %s, %s, %s)",

View File

@@ -143,8 +143,11 @@ polling_auto_trigger:
worker:
role: "all"
instance_name: ""
polling_total_max_concurrency: 100
# 日留存只读演练验收通过前必须保持关闭
audit_retention_cleanup_enabled: false
# 审计归档、Integration 归档与日留存默认关闭,低峰期按单日推进
audit_archive_tasks_enabled: false
# 审批新旧入口切换配置
approval:

View File

@@ -135,7 +135,9 @@ func bindEnvVariables(v *viper.Viper) {
"polling_auto_trigger.auto_trigger_system_user_id",
"worker.role",
"worker.instance_name",
"worker.polling_total_max_concurrency",
"worker.audit_retention_cleanup_enabled",
"worker.audit_archive_tasks_enabled",
"approval.legacy_refund_manual_enabled",
"approval.legacy_offline_recharge_pay_enabled",
"wecom.base_url",

View File

@@ -18,6 +18,12 @@ const PollingDequeueMaxBatchSize = 7000
// 300支撑 10M 卡、2小时 carddata 间隔Gateway 200ms → 300并发 = 1500任务/秒/类型)
const PollingDefaultMaxConcurrency = 300
// PollingDefaultTotalMaxConcurrency 全部轮询任务共享的默认总并发上限。
const PollingDefaultTotalMaxConcurrency = 100
// PollingMaxConcurrencyLimit 轮询并发配置的代码安全上限。
const PollingMaxConcurrencyLimit = 1000
// PollingConcurrencyKeyTTL 并发计数 key 的过期时间(秒)
// 保证 Worker 意外崩溃defer Decr 未执行)时计数器在此时间内自动归零
const PollingConcurrencyKeyTTL = 600 // 10 分钟

View File

@@ -289,6 +289,11 @@ func RedisPollingConcurrencyCurrentKey(taskType string) string {
return fmt.Sprintf("polling:concurrency:current:%s", taskType)
}
// RedisPollingConcurrencyTotalCurrentKey 返回全部轮询共享的并发计数键。
func RedisPollingConcurrencyTotalCurrentKey() string {
return "polling:concurrency:current:total"
}
// RedisPollingManualQueueKey 生成手动触发队列的 Redis 键
// 用途List 存储手动触发的卡 IDFIFO 队列)
// 过期时间:无(临时队列)