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
If we want to add the concurrency limit on the service on the server side, we can do this:
let layer = tower::ServiceBuilder::new()..load_shed().concurrency_limit(2).into_inner();Service::builder().layer(layer).add_service(greeter).add_service(echo).serve(addr).await?;
The above code we have: the greeter and echo service maximum concurrency is 2, both for the connection of concurrent cap of a total of 4, exert the function of each layer service is the same, I understand it right?
Now what if I want to implement different concurrency limits for the greeter and echo services, say 3 for one and 2 for the other? I couldn't find a corresponding method in Tonic's documentation or code.
However, for the TowerService it is possible, I can wrap the two services separately, for example:
let greeter = tower::ServiceBuilder::new().load_shed().concurrency_limit(3).service(greeter);let echo = tower::ServiceBuilder::new().load_shed().concurrency_limit(2).service(echo);Server::builder().add_service(greeter).add_service(echo).serve(addr).await?;
But that won't work. Because add_service() method requires the participation of type must implement the tonic::server::NamedService trait and the Error association type must be Infallible.
How to solve this problem?
Do you have similar needs when using Tonic?
Additionally, I also asked this question on stackoverflow.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
If we want to add the concurrency limit on the service on the server side, we can do this:
The above code we have: the greeter and echo service maximum concurrency is 2, both for the connection of concurrent cap of a total of 4, exert the function of each layer service is the same, I understand it right?
Now what if I want to implement different concurrency limits for the
greeter
andecho
services, say 3 for one and 2 for the other? I couldn't find a corresponding method in Tonic's documentation or code.However, for the Tower
Service
it is possible, I can wrap the two services separately, for example:But that won't work. Because
add_service()
method requires the participation of type must implement thetonic::server::NamedService
trait and theError
association type must beInfallible
.How to solve this problem?
Do you have similar needs when using Tonic?
Additionally, I also asked this question on stackoverflow.
Beta Was this translation helpful? Give feedback.
All reactions