Skip to content

Commit 0b87514

Browse files
committed
Adjust concurrency logic and metrics in the concurrency package, and improve debugging output
1 parent 9d1008b commit 0b87514

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

concurrency/metrics.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,10 @@ func (ch *ConcurrencyHandler) MonitorServerResponseCodes(resp *http.Response) in
157157
defer ch.Metrics.Lock.Unlock()
158158

159159
if statusCode >= 200 && statusCode < 300 {
160+
// Reset error counts for successful responses
160161
ch.Metrics.TotalRateLimitErrors = 0
161162
ch.Metrics.TotalRetries = 0
163+
return 0 // No need to adjust concurrency for successful responses
162164
} else if statusCode >= 500 && statusCode < 600 {
163165
ch.Metrics.TotalRateLimitErrors++
164166
} else if statusCode >= 400 && statusCode < 500 {
@@ -167,8 +169,11 @@ func (ch *ConcurrencyHandler) MonitorServerResponseCodes(resp *http.Response) in
167169

168170
totalRequests := float64(ch.Metrics.TotalRequests)
169171
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+
}
171175

176+
errorRate := totalErrors / totalRequests
172177
ch.Metrics.ResponseCodeMetrics.ErrorRate = errorRate
173178

174179
ch.logger.Debug("Server Response Code Monitoring",
@@ -180,11 +185,9 @@ func (ch *ConcurrencyHandler) MonitorServerResponseCodes(resp *http.Response) in
180185

181186
// Only suggest a scale-down if the error rate exceeds the threshold
182187
if errorRate > ErrorRateThreshold {
183-
return -1
184-
} else if len(ch.sem) < MaxConcurrency {
185-
return 1
188+
return -1 // Suggest decrease concurrency
186189
}
187-
return 0
190+
return 0 // Default to no change if error rate is within acceptable limits
188191
}
189192

190193
// MonitorResponseTimeVariability monitors the response time variability and suggests a concurrency adjustment.

0 commit comments

Comments
 (0)