-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added inflight_requests_limit #2356
Conversation
Signed-off-by: GilboaAWS <gilboabg@amazon.com>
2543a4a
to
9a9580b
Compare
Signed-off-by: GilboaAWS <gilboabg@amazon.com>
9a9580b
to
1b904f8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the detailed description!
How multi-node requests are counted? Single request between client and GLIDE core is converted to multiple requests to server nodes.
The inflight requests limit counts multi-node requests as a single command. This design decision was made to keep the implementation simple and provide a straightforward configuration option for users. This approach strikes a balance between providing a useful feature for controlling the number of concurrent requests and maintaining a reasonable level of complexity in the implementation. However, we recognize the potential need for more granular control and visibility into the request flow. As part of our future roadmap, we plan to introduce telemetry and monitoring capabilities that will provide deeper insights into the request handling process, including the ability to track and analyze multi-node requests in greater detail. This will enable users to better understand the request flow and make more informed decisions regarding the configuration of the inflight requests limit or other performance-related settings. |
|
There is absolutely no need to use fetch_update() when fetch_sub() is sufficient - fetch_update is based on compare_exchange, which is expensive, prone to repetitiveness and ABA problem |
Thanks @ikolomi for the review!
The ABA (ABA Problem) issue is not a concern in this case, as the operation is performed on an AtomicUsize rather than a pointer. Even if the value changes, the
The use of By employing |
This is simply not true - Having counter of negative value for an infinite short time period will not have any negative impact on the performance. On the contrary - using fetch_update() will increases latency due it complex memory bus interaction |
I believe this one will illustrate this negative impact. Thread No.4 could have continued to run without returning an error, but it couldn't because the counter was exceeding the limit at that moment. |
glide-core/src/client/mod.rs
Outdated
@@ -102,6 +105,8 @@ pub enum ClientWrapper { | |||
pub struct Client { | |||
internal_client: ClientWrapper, | |||
request_timeout: Duration, | |||
// Setting this counter to limit the inflight requests, in case of any queue is blocked, so we return error to the customer. | |||
inflight_requests_counter: Arc<AtomicIsize>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not what it counts , so it should be "inflight_requests_allowed"
glide-core/src/client/mod.rs
Outdated
@@ -409,6 +414,28 @@ impl Client { | |||
Err(err) | |||
} | |||
} | |||
|
|||
pub fn reserve_inflight_request(&self) -> bool { | |||
if self.inflight_requests_counter.load(Ordering::SeqCst) < 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if "inflight_requests_allowed" than <=0 should be used
125abe3
to
89b5347
Compare
Signed-off-by: GilboaAWS <gilboabg@amazon.com>
89b5347
to
8ebd92f
Compare
Inflight Requests Limit
This PR introduces a new feature that limits the maximum number of concurrent (inflight) requests sent to Valkey through each connection of a Glide client. This feature is implemented in the Glide infrastructure and is currently supported for the Python client, with plans to extend support to other language clients in the future.
Motivation
Limiting the number of inflight requests per connection can help prevent the queues in the Glide infrastructure from running out of memory (OOM) due to excessive queuing or blocking. When the Glide infrastructure receives more requests than it can handle, it may start queuing requests, leading to increased memory usage and potential OOM situations in the queues. By controlling the number of inflight requests, this feature aims to mitigate the risk of the Glide queues running out of memory and improve overall system stability and reliability.
Implementation
The inflight requests limit is implemented using an atomic counter mechanism. Each connection in a Glide client has an associated atomic counter that keeps track of the number of inflight requests for that connection.
When a new request is initiated, the client attempts to increment the atomic counter associated with the connection. If the counter value after incrementing exceeds the configured inflight requests limit for that connection, the request is rejected with an error, indicating that the maximum inflight requests limit has been reached.
If the counter value after incrementing is within the limit, the request proceeds, and the counter is decremented when the request is completed.
Configuration
The inflight requests limit is configurable and has a default value of 1000 requests per connection. This default value can be overridden by client-specific configuration options, which will be documented separately for each language client.
For the Python client, the
inflight_requests_limit
option has been added to theGlideClusterClientConfiguration
andGlideClientConfiguration
classes, allowing users to specify the desired limit when creating a new client instance.Limitations and Considerations
Future Work