File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -134,13 +134,24 @@ protected override void Dispose(bool disposing)
134
134
135
135
private int CalculateDelay ( )
136
136
{
137
- long ? availablePermits = _concurrencyLimiter . GetStatistics ( ) ? . CurrentAvailablePermits ;
138
- if ( ! ( availablePermits < _throttlingThreshold ) )
137
+ RateLimiterStatistics ? rateLimiterStatistics = _concurrencyLimiter . GetStatistics ( ) ;
138
+ if ( rateLimiterStatistics is null )
139
139
{
140
140
return 0 ;
141
141
}
142
142
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 ) ;
144
155
}
145
156
}
146
157
}
You can’t perform that action at this time.
0 commit comments