@@ -227,11 +227,12 @@ const QUEUE_METRICS_CK_GAUGE_EXTRAS = {
227227} ;
228228
229229// Total-concurrency tail (gauge[10]/gauge[11]): live group cardinality + raw stored cap.
230- // Requires groupConcurrencyKey/totalConcurrencyLimitKey locals; the CK scripts that actually
231- // run (the Tracked variants and the CK dequeue) all declare them for the total-cap gate.
230+ // Requires the groupConcurrencyKey local and the __totalLimitRaw memo (one GET shared with
231+ // the total-cap gate); the CK scripts that run this (the Tracked variants and the CK
232+ // dequeue) declare both. The group SCARD stays a fresh read: it must be post-admission.
232233const QUEUE_METRICS_TOTAL_GAUGE_EXTRAS = {
233234 totalRunning : "redis.call('SCARD', groupConcurrencyKey)" ,
234- totalLimit : "redis.call('GET', totalConcurrencyLimitKey ) or '0'" ,
235+ totalLimit : "__totalLimitRaw( ) or '0'" ,
235236} ;
236237
237238// CK enqueue variants of the two gauges above, extended with the CK-health tail.
@@ -4204,6 +4205,13 @@ local baseQueueKey = KEYS[15]
42044205-- Total-cap keys (KEYS 16-17)
42054206local groupConcurrencyKey = KEYS[16]
42064207local totalConcurrencyLimitKey = KEYS[17]
4208+ local __rawTotalLimit = nil
4209+ local function __totalLimitRaw()
4210+ if __rawTotalLimit == nil then
4211+ __rawTotalLimit = redis.call('GET', totalConcurrencyLimitKey) or false
4212+ end
4213+ return __rawTotalLimit
4214+ end
42074215
42084216local queueName = ARGV[1]
42094217local messageId = ARGV[2]
@@ -4248,7 +4256,7 @@ if enableFastPath == '1' then
42484256 -- slow path (the message queues; the dequeue gate holds it).
42494257 local totalAllowsFastPath = true
42504258 if totalConcurrencyEnabled then
4251- local rawTotalLimit = redis.call('GET', totalConcurrencyLimitKey )
4259+ local rawTotalLimit = __totalLimitRaw( )
42524260 if rawTotalLimit then
42534261 local totalLimit = math.min(tonumber(rawTotalLimit), envLimit)
42544262 if tonumber(redis.call('SCARD', groupConcurrencyKey) or '0') >= totalLimit then
@@ -4375,6 +4383,13 @@ local baseQueueKey = KEYS[16]
43754383-- Total-cap keys (KEYS 17-18)
43764384local groupConcurrencyKey = KEYS[17]
43774385local totalConcurrencyLimitKey = KEYS[18]
4386+ local __rawTotalLimit = nil
4387+ local function __totalLimitRaw()
4388+ if __rawTotalLimit == nil then
4389+ __rawTotalLimit = redis.call('GET', totalConcurrencyLimitKey) or false
4390+ end
4391+ return __rawTotalLimit
4392+ end
43784393
43794394local queueName = ARGV[1]
43804395local messageId = ARGV[2]
@@ -4419,7 +4434,7 @@ if enableFastPath == '1' then
44194434 -- Total-cap gate: see enqueueMessageCkTracked.
44204435 local totalAllowsFastPath = true
44214436 if totalConcurrencyEnabled then
4422- local rawTotalLimit = redis.call('GET', totalConcurrencyLimitKey )
4437+ local rawTotalLimit = __totalLimitRaw( )
44234438 if rawTotalLimit then
44244439 local totalLimit = math.min(tonumber(rawTotalLimit), envLimit)
44254440 if tonumber(redis.call('SCARD', groupConcurrencyKey) or '0') >= totalLimit then
@@ -5087,6 +5102,13 @@ local lengthCounterKey = KEYS[10]
50875102local runningCounterKey = KEYS[11]
50885103local groupConcurrencyKey = KEYS[12]
50895104local totalConcurrencyLimitKey = KEYS[13]
5105+ local __rawTotalLimit = nil
5106+ local function __totalLimitRaw()
5107+ if __rawTotalLimit == nil then
5108+ __rawTotalLimit = redis.call('GET', totalConcurrencyLimitKey) or false
5109+ end
5110+ return __rawTotalLimit
5111+ end
50905112
50915113local ckWildcardName = ARGV[1]
50925114local currentTime = tonumber(ARGV[2])
@@ -5129,7 +5151,7 @@ local actualMaxCount = math.min(maxCount, envAvailableCapacity)
51295151-- behind, and blocking on it would deadlock the run against itself).
51305152local totalHeadroom = nil
51315153if totalConcurrencyEnabled then
5132- local rawTotalLimit = redis.call('GET', totalConcurrencyLimitKey )
5154+ local rawTotalLimit = __totalLimitRaw( )
51335155 if rawTotalLimit then
51345156 local totalConcurrencyLimit = math.min(tonumber(rawTotalLimit), envConcurrencyLimit)
51355157 local groupCurrentConcurrency = tonumber(redis.call('SCARD', groupConcurrencyKey) or '0')
0 commit comments