Skip to content

Commit f258cd0

Browse files
committed
* Expand throttling delay code, add comment.
1 parent 05714b5 commit f258cd0

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

projects/RabbitMQ.Client/ThrottlingRateLimiter.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,24 @@ protected override void Dispose(bool disposing)
134134

135135
private int CalculateDelay()
136136
{
137-
long? availablePermits = _concurrencyLimiter.GetStatistics()?.CurrentAvailablePermits;
138-
if (!(availablePermits < _throttlingThreshold))
137+
RateLimiterStatistics? rateLimiterStatistics = _concurrencyLimiter.GetStatistics();
138+
if (rateLimiterStatistics is null)
139139
{
140140
return 0;
141141
}
142142

143-
return (int)((1.0 - availablePermits / (double)_maxConcurrency) * 1000);
143+
long availablePermits = rateLimiterStatistics.CurrentAvailablePermits;
144+
if (availablePermits >= _throttlingThreshold)
145+
{
146+
/*
147+
* Note: do NOT add a delay because available permits exceeeds the threshold
148+
* below which throttling begins
149+
*/
150+
return 0;
151+
}
152+
153+
double percentageUsed = 1.0 - (availablePermits / (double)_maxConcurrency);
154+
return (int)(percentageUsed * 100);
144155
}
145156
}
146157
}

0 commit comments

Comments
 (0)