Skip to content

Commit 9d1008b

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

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

concurrency/metrics.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (ch *ConcurrencyHandler) EvaluateAndAdjustConcurrency(resp *http.Response,
5858
// Calculate the cumulative score.
5959
cumulativeScore := weightedRateLimitScore + weightedResponseCodeScore + weightedResponseTimeScore
6060

61-
// Log the feedback from each monitoring function for debugging.
61+
// Detailed debugging output
6262
ch.logger.Debug("Evaluate and Adjust Concurrency",
6363
zap.String("event", "EvaluateConcurrency"),
6464
zap.Float64("weightedRateLimitScore", weightedRateLimitScore),
@@ -71,6 +71,14 @@ func (ch *ConcurrencyHandler) EvaluateAndAdjustConcurrency(resp *http.Response,
7171
zap.Duration("responseTime", responseTime),
7272
)
7373

74+
// Check for successful response and log appropriately
75+
if responseCodeFeedback == 1 { // Assuming 1 indicates success
76+
ch.logger.Info("Successful response noted, checking for scaling necessity.",
77+
zap.String("API Response", "Success"),
78+
zap.Int("StatusCode", resp.StatusCode),
79+
)
80+
}
81+
7482
// Check critical thresholds
7583
if rateLimitFeedback <= RateLimitCriticalThreshold || weightedResponseCodeScore >= ErrorResponseThreshold {
7684
ch.logger.Warn("Scaling down due to critical threshold breach",
@@ -82,7 +90,7 @@ func (ch *ConcurrencyHandler) EvaluateAndAdjustConcurrency(resp *http.Response,
8290
return
8391
}
8492

85-
// Evaluate cumulative impact and make a scaling decision.
93+
// Evaluate cumulative impact and make a scaling decision based on the cumulative score and other metrics.
8694
if cumulativeScore < 0 {
8795
utilizedBefore := len(ch.sem) // Tokens in use before scaling down.
8896
ch.ScaleDown()
@@ -170,9 +178,10 @@ func (ch *ConcurrencyHandler) MonitorServerResponseCodes(resp *http.Response) in
170178
zap.Float64("ErrorRate", errorRate),
171179
)
172180

181+
// Only suggest a scale-down if the error rate exceeds the threshold
173182
if errorRate > ErrorRateThreshold {
174183
return -1
175-
} else if errorRate <= ErrorRateThreshold && len(ch.sem) < MaxConcurrency {
184+
} else if len(ch.sem) < MaxConcurrency {
176185
return 1
177186
}
178187
return 0

0 commit comments

Comments
 (0)