File tree Expand file tree Collapse file tree 2 files changed +13
-3
lines changed
Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ type ConcurrencyMetrics struct {
4242 Lock sync.Mutex // Lock for response time variability metrics
4343 StdDevThreshold float64 // Maximum acceptable standard deviation for adjusting concurrency
4444 DebounceScaleDownCount int // Counter to manage scale down actions after consecutive triggers
45+ DebounceScaleUpCount int // Counter to manage scale up actions after consecutive triggers
4546 }
4647 ResponseCodeMetrics struct {
4748 ErrorRate float64 // Error rate calculated as (TotalRateLimitErrors + 5xxErrors) / TotalRequests
Original file line number Diff line number Diff line change @@ -225,7 +225,7 @@ func (ch *ConcurrencyHandler) MonitorResponseTimeVariability(responseTime time.D
225225 stdDev := calculateStdDev (responseTimes )
226226 averageResponseTime := calculateAverage (responseTimes )
227227
228- // Multi-factor check before scaling down
228+ // Check if conditions suggest a need to scale down
229229 if stdDev > ch .Metrics .ResponseTimeVariability .StdDevThreshold && averageResponseTime > AcceptableAverageResponseTime {
230230 ch .Metrics .ResponseTimeVariability .DebounceScaleDownCount ++
231231 if ch .Metrics .ResponseTimeVariability .DebounceScaleDownCount >= debounceScaleDownThreshold {
@@ -234,10 +234,19 @@ func (ch *ConcurrencyHandler) MonitorResponseTimeVariability(responseTime time.D
234234 }
235235 } else {
236236 ch .Metrics .ResponseTimeVariability .DebounceScaleDownCount = 0 // Reset counter if conditions are not met
237- if stdDev <= ch .Metrics .ResponseTimeVariability .StdDevThreshold {
238- return 1 // Suggest increase concurrency if conditions are favorable
237+ }
238+
239+ // Check if conditions suggest a need to scale up
240+ if stdDev <= ch .Metrics .ResponseTimeVariability .StdDevThreshold && averageResponseTime <= AcceptableAverageResponseTime {
241+ ch .Metrics .ResponseTimeVariability .DebounceScaleUpCount ++
242+ if ch .Metrics .ResponseTimeVariability .DebounceScaleUpCount >= debounceScaleDownThreshold {
243+ ch .Metrics .ResponseTimeVariability .DebounceScaleUpCount = 0
244+ return 1 // Suggest increase concurrency
239245 }
246+ } else {
247+ ch .Metrics .ResponseTimeVariability .DebounceScaleUpCount = 0 // Reset counter if conditions are not met
240248 }
249+
241250 return 0 // Default to no change
242251}
243252
You can’t perform that action at this time.
0 commit comments