You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: concurrency/metrics.go
+60-4
Original file line number
Diff line number
Diff line change
@@ -197,8 +197,20 @@ func (ch *ConcurrencyHandler) MonitorServerResponseCodes(resp *http.Response) in
197
197
varresponseTimes []time.Duration
198
198
varresponseTimesLock sync.Mutex
199
199
200
-
// MonitorResponseTimeVariability monitors the response time variability and suggests a concurrency adjustment.
201
-
// MonitorResponseTimeVariability monitors the response time variability and suggests a concurrency adjustment.
200
+
// MonitorResponseTimeVariability assesses the response time variability from a series of HTTP requests and decides whether to adjust the concurrency level of outgoing requests. This function is integral to maintaining optimal system performance under varying load conditions.
201
+
//
202
+
// The function first appends the latest response time to a sliding window of the last 10 response times to maintain a recent history. It then calculates the standard deviation and the average of these times. The standard deviation helps determine the variability or consistency of response times, while the average gives a central tendency.
203
+
//
204
+
// Based on these calculated metrics, the function employs a multi-factor decision mechanism:
205
+
// - If the standard deviation exceeds a pre-defined threshold and the average response time is greater than an acceptable maximum, a debounce counter is incremented. This counter must reach a predefined threshold (debounceScaleDownThreshold) before a decision to decrease concurrency is made, ensuring that only sustained negative trends lead to a scale down.
206
+
// - If the standard deviation is below or equal to the threshold, suggesting stable response times, and the system is currently operating below its concurrency capacity, it may suggest an increase in concurrency to improve throughput.
207
+
//
208
+
// This approach aims to prevent transient spikes in response times from causing undue scaling actions, thus stabilizing the overall performance and responsiveness of the system.
209
+
//
210
+
// Returns:
211
+
// - (-1) to suggest a decrease in concurrency,
212
+
// - (1) to suggest an increase in concurrency,
213
+
// - (0) to indicate no change needed.
202
214
func (ch*ConcurrencyHandler) MonitorResponseTimeVariability(responseTime time.Duration) int {
0 commit comments