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: httpclient/httpclient_concurrency_management.go
+53-34Lines changed: 53 additions & 34 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,7 @@
1
1
// http_concurrency_management.go
2
2
// package httpclient provides utilities to manage HTTP client interactions, including concurrency control.
3
-
// The Concurrency Manager ensures no more than a certain number of concurrent requests (e.g., 5 for Jamf Pro) are sent at the same time. This is managed using a semaphore
3
+
// The Concurrency Manager ensures no more than a certain number of concurrent requests
4
+
// (e.g., 5 for Jamf Pro) are sent at the same time. This is managed using a semaphore
4
5
package httpclient
5
6
6
7
import (
@@ -42,23 +43,47 @@ type requestIDKey struct{}
42
43
43
44
// Functions:
44
45
45
-
// AcquireConcurrencyToken attempts to acquire a token from the ConcurrencyManager to manage the number of concurrent requests.
46
-
// This function is designed to ensure that the HTTP client adheres to predefined concurrency limits, preventing an excessive number of simultaneous requests.
47
-
// It creates a new context with a timeout to avoid indefinite blocking in case the concurrency limit is reached.
48
-
// Upon successfully acquiring a token, it records the time taken to acquire the token and updates performance metrics accordingly.
49
-
// The function then adds the acquired request ID to the context, which can be used for tracking and managing individual requests.
46
+
// NewConcurrencyManager initializes a new ConcurrencyManager with the given
47
+
// concurrency limit, logger, and debug mode. The ConcurrencyManager ensures
48
+
// no more than a certain number of concurrent requests are made.
// AcquireConcurrencyToken attempts to acquire a token from the ConcurrencyManager
60
+
// to manage the number of concurrent requests. This function is designed to ensure
61
+
// that the HTTP client adheres to predefined concurrency limits, preventing an
62
+
// excessive number of simultaneous requests. It creates a new context with a timeout
63
+
// to avoid indefinite blocking in case the concurrency limit is reached.
64
+
// Upon successfully acquiring a token, it records the time taken to acquire the
65
+
// token and updates performance metrics accordingly. The function then adds the
66
+
// acquired request ID to the context, which can be used for tracking and managing
67
+
// individual requests.
50
68
//
51
69
// Parameters:
52
-
// - ctx: The parent context from which the new context with timeout will be derived. This allows for proper request cancellation and timeout handling.
53
-
// - log: An instance of a logger (conforming to the logger.Logger interface), used to log relevant information and errors during the token acquisition process.
70
+
// - ctx: The parent context from which the new context with timeout will be derived.
71
+
// This allows for proper request cancellation and timeout handling.
72
+
//
73
+
// - log: An instance of a logger (conforming to the logger.Logger interface), used
74
+
// to log relevant information and errors during the token acquisition process.
54
75
//
55
76
// Returns:
56
-
// - A new context containing the acquired request ID, which should be passed to subsequent operations requiring concurrency control.
57
-
// - An error if the token could not be acquired within the timeout period or due to any other issues encountered by the ConcurrencyManager.
77
+
// - A new context containing the acquired request ID, which should be passed to
// HistoricalAverageAcquisitionTime computes the average time taken to acquire a token from the semaphore over a historical period (e.g., the last 5 minutes).
200
-
// It helps in understanding the historical contention for tokens and can be used to adjust concurrency limits.
213
+
// HistoricalAverageAcquisitionTime computes the average time taken to acquire
214
+
// a token from the semaphore over a historical period (e.g., the last 5 minutes).
215
+
// It helps in understanding the historical contention for tokens and can be used
0 commit comments