缓解io压力
This commit is contained in:
@@ -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)",
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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 分钟
|
||||
|
||||
@@ -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 存储手动触发的卡 ID(FIFO 队列)
|
||||
// 过期时间:无(临时队列)
|
||||
|
||||
Reference in New Issue
Block a user