Skip to content
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

Add support for load-shedding. #1616

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

abizjak
Copy link

@abizjak abizjak commented Jan 30, 2024

Add an option to enable load shedding for the service constructed for the connection.

Motivation

In the server we are implementing we want to load-shed when the service is overloaded, and we want to limit the number of concurrent requests per connection. We use tower::load_shed layer for load shedding, but this only applies to the entire service.

If we additionally apply the per-connection concurrency limit the issue is that this limit is typically hit first and so the service responds with "not ready". As a result the load-shed layer of the service is never reached meaning that requests just queue up.

Solution

The solution is to optionally add a load-shed layer to the per-connection service constructed by tonic.

When the per-connection service is not ready this gives an option of immediately
rejecting requests.
@MintuJ
Copy link

MintuJ commented Aug 14, 2024

Setting load_shed on the tower::ServiceBuilder like the example in https://docs.rs/tonic/latest/tonic/transport/struct.Server.html#method.layer will result in an internal error status code. This integration would help in returning a more meaningful error code resource_exhausted.

@abizjak did you get a chance to work on this issue?

@@ -73,7 +73,7 @@ h2 = {version = "0.3.17", optional = true}
hyper = {version = "0.14.26", features = ["full"], optional = true}
hyper-timeout = {version = "0.4", optional = true}
tokio-stream = "0.1"
tower = {version = "0.4.7", default-features = false, features = ["balance", "buffer", "discover", "limit", "load", "make", "timeout", "util"], optional = true}
tower = {version = "0.4.7", default-features = false, features = ["balance", "buffer", "discover", "limit", "load", "make", "timeout", "util", "load-shed"], optional = true}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep the features here in alphabetic order?

let err = match err.downcast::<tower::load_shed::error::Overloaded>() {
Ok(_) => {
return Ok(Status::resource_exhausted(
"Too many active requests for the connection",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the majority of our messages are lowercase, so please match that here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants