@@ -209,11 +209,12 @@ const QUEUE_METRICS_CK_GAUGE_EXTRAS = {
209209} ;
210210
211211// Total-concurrency tail (gauge[10]/gauge[11]): live group cardinality + raw stored cap.
212- // Requires groupConcurrencyKey/totalConcurrencyLimitKey locals; the CK scripts that actually
213- // run (the Tracked variants and the CK dequeue) all declare them for the total-cap gate.
212+ // Requires the groupConcurrencyKey local and the __totalLimitRaw memo (one GET shared with
213+ // the total-cap gate); the CK scripts that run this (the Tracked variants and the CK
214+ // dequeue) declare both. The group SCARD stays a fresh read: it must be post-admission.
214215const QUEUE_METRICS_TOTAL_GAUGE_EXTRAS = {
215216 totalRunning : "redis.call('SCARD', groupConcurrencyKey)" ,
216- totalLimit : "redis.call('GET', totalConcurrencyLimitKey ) or '0'" ,
217+ totalLimit : "__totalLimitRaw( ) or '0'" ,
217218} ;
218219
219220// CK enqueue variants of the two gauges above, extended with the CK-health tail.
@@ -4118,6 +4119,13 @@ local baseQueueKey = KEYS[15]
41184119-- Total-cap keys (KEYS 16-17)
41194120local groupConcurrencyKey = KEYS[16]
41204121local totalConcurrencyLimitKey = KEYS[17]
4122+ local __rawTotalLimit = nil
4123+ local function __totalLimitRaw()
4124+ if __rawTotalLimit == nil then
4125+ __rawTotalLimit = redis.call('GET', totalConcurrencyLimitKey) or false
4126+ end
4127+ return __rawTotalLimit
4128+ end
41214129
41224130local queueName = ARGV[1]
41234131local messageId = ARGV[2]
@@ -4162,7 +4170,7 @@ if enableFastPath == '1' then
41624170 -- slow path (the message queues; the dequeue gate holds it).
41634171 local totalAllowsFastPath = true
41644172 if totalConcurrencyEnabled then
4165- local rawTotalLimit = redis.call('GET', totalConcurrencyLimitKey )
4173+ local rawTotalLimit = __totalLimitRaw( )
41664174 if rawTotalLimit then
41674175 local totalLimit = math.min(tonumber(rawTotalLimit), envLimit)
41684176 if tonumber(redis.call('SCARD', groupConcurrencyKey) or '0') >= totalLimit then
@@ -4289,6 +4297,13 @@ local baseQueueKey = KEYS[16]
42894297-- Total-cap keys (KEYS 17-18)
42904298local groupConcurrencyKey = KEYS[17]
42914299local totalConcurrencyLimitKey = KEYS[18]
4300+ local __rawTotalLimit = nil
4301+ local function __totalLimitRaw()
4302+ if __rawTotalLimit == nil then
4303+ __rawTotalLimit = redis.call('GET', totalConcurrencyLimitKey) or false
4304+ end
4305+ return __rawTotalLimit
4306+ end
42924307
42934308local queueName = ARGV[1]
42944309local messageId = ARGV[2]
@@ -4333,7 +4348,7 @@ if enableFastPath == '1' then
43334348 -- Total-cap gate: see enqueueMessageCkTracked.
43344349 local totalAllowsFastPath = true
43354350 if totalConcurrencyEnabled then
4336- local rawTotalLimit = redis.call('GET', totalConcurrencyLimitKey )
4351+ local rawTotalLimit = __totalLimitRaw( )
43374352 if rawTotalLimit then
43384353 local totalLimit = math.min(tonumber(rawTotalLimit), envLimit)
43394354 if tonumber(redis.call('SCARD', groupConcurrencyKey) or '0') >= totalLimit then
@@ -4972,6 +4987,13 @@ local lengthCounterKey = KEYS[10]
49724987local runningCounterKey = KEYS[11]
49734988local groupConcurrencyKey = KEYS[12]
49744989local totalConcurrencyLimitKey = KEYS[13]
4990+ local __rawTotalLimit = nil
4991+ local function __totalLimitRaw()
4992+ if __rawTotalLimit == nil then
4993+ __rawTotalLimit = redis.call('GET', totalConcurrencyLimitKey) or false
4994+ end
4995+ return __rawTotalLimit
4996+ end
49754997
49764998local ckWildcardName = ARGV[1]
49774999local currentTime = tonumber(ARGV[2])
@@ -5014,7 +5036,7 @@ local actualMaxCount = math.min(maxCount, envAvailableCapacity)
50145036-- behind, and blocking on it would deadlock the run against itself).
50155037local totalHeadroom = nil
50165038if totalConcurrencyEnabled then
5017- local rawTotalLimit = redis.call('GET', totalConcurrencyLimitKey )
5039+ local rawTotalLimit = __totalLimitRaw( )
50185040 if rawTotalLimit then
50195041 local totalConcurrencyLimit = math.min(tonumber(rawTotalLimit), envConcurrencyLimit)
50205042 local groupCurrentConcurrency = tonumber(redis.call('SCARD', groupConcurrencyKey) or '0')
0 commit comments