@@ -157,8 +157,10 @@ func (ch *ConcurrencyHandler) MonitorServerResponseCodes(resp *http.Response) in
157
157
defer ch .Metrics .Lock .Unlock ()
158
158
159
159
if statusCode >= 200 && statusCode < 300 {
160
+ // Reset error counts for successful responses
160
161
ch .Metrics .TotalRateLimitErrors = 0
161
162
ch .Metrics .TotalRetries = 0
163
+ return 0 // No need to adjust concurrency for successful responses
162
164
} else if statusCode >= 500 && statusCode < 600 {
163
165
ch .Metrics .TotalRateLimitErrors ++
164
166
} else if statusCode >= 400 && statusCode < 500 {
@@ -167,8 +169,11 @@ func (ch *ConcurrencyHandler) MonitorServerResponseCodes(resp *http.Response) in
167
169
168
170
totalRequests := float64 (ch .Metrics .TotalRequests )
169
171
totalErrors := float64 (ch .Metrics .TotalRateLimitErrors + ch .Metrics .TotalRetries )
170
- errorRate := totalErrors / totalRequests
172
+ if totalErrors == 0 {
173
+ return 0 // No errors, no concurrency adjustment needed
174
+ }
171
175
176
+ errorRate := totalErrors / totalRequests
172
177
ch .Metrics .ResponseCodeMetrics .ErrorRate = errorRate
173
178
174
179
ch .logger .Debug ("Server Response Code Monitoring" ,
@@ -180,11 +185,9 @@ func (ch *ConcurrencyHandler) MonitorServerResponseCodes(resp *http.Response) in
180
185
181
186
// Only suggest a scale-down if the error rate exceeds the threshold
182
187
if errorRate > ErrorRateThreshold {
183
- return - 1
184
- } else if len (ch .sem ) < MaxConcurrency {
185
- return 1
188
+ return - 1 // Suggest decrease concurrency
186
189
}
187
- return 0
190
+ return 0 // Default to no change if error rate is within acceptable limits
188
191
}
189
192
190
193
// MonitorResponseTimeVariability monitors the response time variability and suggests a concurrency adjustment.
0 commit comments